|
Seqlist.h
#include<iostream.h>
class SeqList
{
private:
int *table;
int size;
int len;
public:
SeqList(int n=0);
~SeqList(void);
bool isEmpty()const;
bool isFull()const;
int length()const;
int get(int i)const;
bool set(int i,int k);
bool insert(int i,int k);
bool insert(int k);
int search(int k);
bool remove(int k);
void create(int n);
void output();
};
SeqList::SeqList(int n)
{
table=new int[n];
size=n;
len=0;
}
SeqList::~SeqList(void)
{
delete []table;
}
bool SeqList::isEmpty()const
{
return len==0;
}
bool SeqList::isFull()const
{
return len>=size;
}
int SeqList::length()const
{
return len;
}
int SeqList::get(int i)const
{
if(i>0&&i<=len)
{
return table[i-1];
}
else
{
return -1;
}
}
bool SeqList::set(int i,int k)
{
if(i>0&&i<=len)
{
table[i-1]=k;
return true;
}
else
{
return false;
}
}
int SeqList::search(int k)
{
int i=1;
while(i<=length()&&get(i)!=k)
{
i++;
}
if(i<=length())
{
return i;
}
else
{
return 0;
}
}
bool SeqList::insert(int i,int k)
{
if(!isFull())
{
if(i<=0)
{
i=1;
}
if(i>len)
{
i=len+1;
}
for(int j=len-1;j>=i-1;j--)
{
table[j+1]=table[j];
}
table[i-1]=k;
len++;
return true;
}
else
{
cerr<<"顺序表已满,无法插入"<<k<<"值!\n";
return false;
}
}
bool SeqList::insert(int k)
{
return insert(length()+1,k);
}
bool SeqList::remove(int k)
{
if(!isEmpty())
{
int i=search(k);
for(int j=i;j<length();j++)
{
set(j,get(j+1));
}
len--;
return true;
}
else
{
cout<<"顺序表为空,无法删除!\n";
return false;
}
}
void SeqList::create(int n)
{
for(int i=0;i<n;i++)
{
table=i+1;
len++;
}
}
void SeqList:utput()
{
for(int i=0;i<length();i++)
{
cout<<table<<" ";
}
cout<<endl;
}
错误:
编译器: Default compiler
执行 g++.exe...
g++.exe "E:\32.cpp" -o "E:\32.exe" -I"d:\Dev-Cpp\include\c++" -I"d:\Dev-Cpp\include\c++\mingw32" -I"d:\Dev-Cpp\include\c++\backward" -I"d:\Dev-Cpp\include" -L"d:\Dev-Cpp\lib"
d:\Dev-Cpp\lib/libmingw32.a(main.o)(.text+0x7f):main.c: undefined reference to `WinMain@16'
执行结束
[[italic] 本帖最后由 wfjt 于 2007-12-10 11:26 编辑 [/italic]] |
|