C++リニアテーブルの操作を実現

1552 ワード

#include
#include

typedef int ElemType;

struct List 
{
	ElemType *list;	//                
	int size;	//      
	int MaxSize;	//  list     
};

 //   L  
void InitList(List &L)
{
	 L.MaxSize=10;	//     
	 L.list=new ElemType[L.MaxSize];	//      
	 if(L.list==NULL)
	 {
		cout<L.size)
	{
		cerr<L.size+1)
	{
		cout<item)
				break;
		}
		pos=i+1;
	}
	else if(pos==-1)	//    
	{
		pos=L.size+1;
	}
	//      ,             
	if(L.size==L.MaxSize)
	{
		int k=sizeof(ElemType);	//             
		L.list=(ElemType*)realloc(L.list, 2*L.MaxSize*k);
		if(L.list==NULL)
		{
			cout<=pos-1; i--)
	{
		L.list[i+1]=L.list[i];
	}
	// item           pos-1   
	L.list[pos-1]=item;
	L.size++;	//       1
	return true;	//   ,      
} 

// L     
bool DeleteList(List &L, ElemType item, int pos)
{
	if(L.size==0)	//         
	{
		cout<L.size+1)
	{
		cout<10)
	{
		int k= sizeof(ElemType);
		L.list=(ElemType*)realloc(L.list, L.MaxSize*k/2);
	}
	L.MaxSize=L.MaxSize/2;	//                
	return true;	//   ,      
}

// L              
void SortList(List &L)
{
	int i,j;
	ElemType x;
	for(i=1; i=0; j--)	//           
		{
			if(x>x;
	if(FindList(t,x)) cout<>x;
	if(DeleteList(t,x,0)) cout<>x;
	if(InsertList(t,x,0)) cout<

実行結果: