
数据库程序设计C++
一、设计一个静态链表(或成为数组链表),该链表储存的数据类型为string,请实现以下的功能。public:List();//构造函数intsize()const;//返...
一、设计一个静态链表(或成为数组链表),该链表储存的数据类型为string,请实现以下的功能。
public:
List();//构造函数
int size() const; //返回链表的长度
bool full() const; //返回链表是否已满
bool empty() const; //返回链表是否已空
void clear(); //清空链表
int retrieve( int position, string &x ) const;//获取链表第position位置的元素到x,成功返回0,否则返回-1
int replace( int position, const string &x );//将链表第position位置的元素换为x,成功返回0,否则返回-1
int remove( int position, string &x );//获取并删除链表第position位置的元素,成功返回0,否则返回-1
int insert( int position, const string &x );//将元素x插入到链表第position位置,成功返回0,否则返回-1
protected:
int new_node(); //返回链表的数据载体(数组)的可用index,如果链表已满则返回-1
void delete_node( int index); //删除链表数据载体(数组)index位置的元素
int current_position( int index) const;//返回链表数据载体(数组)index位置的元素是链表的哪个位置,如果当前位置没有存放数据,则返回-1
int set_position( int position) const;//返回链表第position位置的数据所存放的数组index,如果不存在position位置,则返回-1
哪位高手帮助一下 必高分重谢
不一定要管不写出、相类似的函数可以只写一个 另外的简单提示就好 展开
public:
List();//构造函数
int size() const; //返回链表的长度
bool full() const; //返回链表是否已满
bool empty() const; //返回链表是否已空
void clear(); //清空链表
int retrieve( int position, string &x ) const;//获取链表第position位置的元素到x,成功返回0,否则返回-1
int replace( int position, const string &x );//将链表第position位置的元素换为x,成功返回0,否则返回-1
int remove( int position, string &x );//获取并删除链表第position位置的元素,成功返回0,否则返回-1
int insert( int position, const string &x );//将元素x插入到链表第position位置,成功返回0,否则返回-1
protected:
int new_node(); //返回链表的数据载体(数组)的可用index,如果链表已满则返回-1
void delete_node( int index); //删除链表数据载体(数组)index位置的元素
int current_position( int index) const;//返回链表数据载体(数组)index位置的元素是链表的哪个位置,如果当前位置没有存放数据,则返回-1
int set_position( int position) const;//返回链表第position位置的数据所存放的数组index,如果不存在position位置,则返回-1
哪位高手帮助一下 必高分重谢
不一定要管不写出、相类似的函数可以只写一个 另外的简单提示就好 展开
3个回答
展开全部
#include <string>
using namespace std;
class List
{
public:
string *strList;
int iListLong;
int iListUseNum;
List();//构造函数
int size() const; //返回链表的长度
bool full() const; //返回链表是否已满
bool empty() const; //返回链表是否已空
void clear(); //清空链表
int retrieve( int position, string &x ) const;//获取链表第position位置的元素到x,成功返回0,否则返回-1
// int replace( int position, const string &x );//将链表第position位置的元素换为x,成功返回0,否则返回-1
// int remove( int position, string &x );//获取并删除链表第position位置的元素,成功返回0,否则返回-1
// int insert( int position, const string &x );//将元素x插入到链表第position位置,成功返回0,否则返回-1
protected:
int new_node(); //返回链表的数据载体(数组)的可用index,如果链表已满则返回-1
// void delete_node( int index); //删除链表数据载体(数组)index位置的元素
// int current_position( int index) const;//返回链表数据载体(数组)index位置的元素是链表的哪个位置,如果当前位置没有存放数据,则返回-1
// int set_position( int position) const;//返回链表第position位置的数据所存放的数组index,如果不存在position位置,则返回-1
};
List::List()
{
iListUseNum = 0;
iListLong = 100;
strList = new string[iListLong];
}
int List::size() const
{
return iListLong;
}
bool List::full() const
{
if (iListUseNum<iListLong)
{
return false;
}
else
{
return true;
}
}
bool List::empty() const
{
if (iListUseNum >= iListLong)
{
return true;
}
else
{
return false;
}
}
void List::clear()
{
for (int i=0; i<iListLong; i++)
{
strList[i].clear();
}
}
int List::retrieve(int position, string &x) const
{
x = strList[position];
if (x.empty())
{
return -1;
}
return 0;
}
int List::new_node()
{
for (int i=0; i<iListLong; i<0)
{
if (string.empty())
{
return i;
}
}
return -1;
}
写法都差不多都是操作数组.
using namespace std;
class List
{
public:
string *strList;
int iListLong;
int iListUseNum;
List();//构造函数
int size() const; //返回链表的长度
bool full() const; //返回链表是否已满
bool empty() const; //返回链表是否已空
void clear(); //清空链表
int retrieve( int position, string &x ) const;//获取链表第position位置的元素到x,成功返回0,否则返回-1
// int replace( int position, const string &x );//将链表第position位置的元素换为x,成功返回0,否则返回-1
// int remove( int position, string &x );//获取并删除链表第position位置的元素,成功返回0,否则返回-1
// int insert( int position, const string &x );//将元素x插入到链表第position位置,成功返回0,否则返回-1
protected:
int new_node(); //返回链表的数据载体(数组)的可用index,如果链表已满则返回-1
// void delete_node( int index); //删除链表数据载体(数组)index位置的元素
// int current_position( int index) const;//返回链表数据载体(数组)index位置的元素是链表的哪个位置,如果当前位置没有存放数据,则返回-1
// int set_position( int position) const;//返回链表第position位置的数据所存放的数组index,如果不存在position位置,则返回-1
};
List::List()
{
iListUseNum = 0;
iListLong = 100;
strList = new string[iListLong];
}
int List::size() const
{
return iListLong;
}
bool List::full() const
{
if (iListUseNum<iListLong)
{
return false;
}
else
{
return true;
}
}
bool List::empty() const
{
if (iListUseNum >= iListLong)
{
return true;
}
else
{
return false;
}
}
void List::clear()
{
for (int i=0; i<iListLong; i++)
{
strList[i].clear();
}
}
int List::retrieve(int position, string &x) const
{
x = strList[position];
if (x.empty())
{
return -1;
}
return 0;
}
int List::new_node()
{
for (int i=0; i<iListLong; i<0)
{
if (string.empty())
{
return i;
}
}
return -1;
}
写法都差不多都是操作数组.

2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
展开全部
实在太多,如果你有严蔚敏版的<数据结构C语言版>的书的话,这些基本相当于那本书的第二章了,去借下来看看吧,这些算法都有
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
C++有这么多容器可以选择,自己做个链表好像没啥意义,除非你是练习数据结构。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询