亚洲精品成人18久久久久_日韩欧美色_江苏极品身材白嫩少妇自拍_曰本人做爰大片免费观看一老师_久草视频网_最近中文字幕MV高清在线视频

首頁 > 考試輔導 > 計算機考試 > 軟件水平考試 > 軟件水平學習指南 > 使用C++實現線性表的基本功能

使用C++實現線性表的基本功能

#include <iostream.h>
#include <conio.h>
#include <alloc.h>
typedef int elemtype;
//線性表的基本操作
void initiallist(elemtype *l);
int isempty(elemtype *l);
void listtraverse(elemtype *l);
int nextelem(elemtype *l);
int priorelem(elemtype *l);
int locateelem(elemtype *l,elemtype &e);
void getelem(elemtype *l);
void listinsert(elemtype *l);
void listdelete(elemtype *l);
void clearlist(elemtype *l);
const int n=10;
elemtype temp;//全局變量!
void initiallist(elemtype *l)
{
for(int i=0;i<n;i++)
*(l+i)='#';
}
int isempty(elemtype *l)
{
if(*l=='#')
return 1;
else
return 0;
}
void listtraverse(elemtype *l)
{
static int k;
if(*(l)==35)
cout<<"the list is null!\n";
else
{
cout<<"the records of the list are:\n";
for(int i=0;i<n+k;i++)
{
if((*(l+i)>32768))
break;
else
cout<<*(l+i)<<" ";
}
k++;
}
}
int nextelem(elemtype *l)
{
int index;
elemtype e;
cout<<"input the records for searching it's next elem!\n";
cin>>e;
index=locateelem(l,e);
if(*(l+index+1)>32768)
cout<<"it has no next elem!\n";
else
cout<<e<<"的后繼是:"<<*(l+index+1)<<endl;
}

int priorelem(elemtype *l)
{
int index;
elemtype e;
cout<<"input the records for searching it's prior elem!\n";
cin>>e;
index=locateelem(l,e);
if(index>n)
cout<<"it has no next elem!\n";
else if(index==-1||index==0)
{
cout<<"it has no prior elem!\n";
return 0;
}
else
cout<<e<<"的前驅是:"<<*(l+index-1)<<endl;
}
int locateelem(elemtype *l,elemtype &e)
{
int i;
for(i=0;i<n+1&&(*(l+i)!='#');i++)
{
if(*(l+i)==e)
return i;
else
continue;
}
if(i<n||i>=n)
return -1;
return i;
}
void getelem(elemtype *l)
{
int index;
cout<<"input the value of i:\n";
cin>>index;
if(*(l+index-1)>32768)
cout<<"the records null!\n";
else
cout<<"the records which you want to search are: "<<*(l+index-1)<<endl;
}
void listinsert(elemtype *l)
{
elemtype e;
int index,i;
cout<<"please input only one inserted number and it's location!\n";
cin>>e;
cin>>index;
if(index>n)
*(l+index-1)=e;
else
{
for(i=n;i>=index;i--)
*(l+i)=*(l+i-1);
*(l+index-1)=e;
}
listtraverse(l);
}
void listdelete(elemtype *l)
{
elemtype e;
int index,i;
cout<<"input the number which you want to deleted!\n";
cin>>e;
index=locateelem(l,e);
for(i=index;i<n+1&&(*(l+i)!='#');i++)
*(l+i-1)=*(l+i);
cout<<"deleted "<<e<<endl;
listtraverse(l);
}
void clearlist(elemtype *l)
{
for(int i=0;i<n+1;i++)
*(l+i)='#';
}
int main()
{
int choice,flag=0;
char ch;
elemtype *p,e;
p=(elemtype *)malloc((n+1)*sizeof(elemtype));
if(!p)
{
cout<<"no more memory can be obtained!\n";
goto loop;
}
loop: p=(elemtype *)realloc(p,(n+1)*sizeof(elemtype));
if(!p)
{
cout<<"overflow!\n";
exit(0);
}
initiallist(p);
cout<<"input "<<n<<" records!\n";//數據互不相同!
for(int i=0;i<n;i++)
cin>>*(p+i);
if(isempty(p))
cout<<"the list is null!\n";
cout<<" menu fuction \n"
<<" 1: 遍歷線性表的元素!( 只允許調用一次!)\n"
<<" 2: 求某一元素的前驅和后繼!\n"
<<" 3: 獲取線性表l中的第i個數據元素內容!\n"
<<" 4: 在線性表中插入一個元素!\n"
<<" 5: 刪除線性表中值為e的元素!\n"
<<" 6: 檢索值為e的數據元素!\n"
<<" 7: 清空線性表!"<<endl;
do
{
cout<<"please input your choice!\n";
cin>>choice;
switch(choice)
{
case 1: listtraverse(p); break;
case 2: nextelem(p);
priorelem(p);
break;
case 3: getelem(p); break;
case 4: listinsert(p); break;
case 5: listdelete(p); break;
case 6:
cout<<"input the records !\n" ;
cin>>e;
cout<<"it's location is "<<locateelem(p,e)+1;
break;
case 7: clearlist(p);
cout<<"now ";
listtraverse(p);
break;
}

cout<<"\ndid you want to continue the operation?(y/n)\n";
cin>>ch;
if(ch=='y'||ch=='y')
flag=1;
else
flag=0;
}while(flag);
free(p);
getch();
return 0;
}

主站蜘蛛池模板: 日本黄色视频在线网址 | 欧美阿v高清资源在线 | 无码熟妇人妻AV在线影片最多 | 欧美一区成人 | 亚洲美女自拍视频 | 国产精品成人自拍 | 日本丰满少妇裸体自慰 | 国产精品露脸国语对白 | 国产成人精品久久亚洲高清不卡p | 国产BBAAAAA片 | 在线观看一区二区三区国产免费 | 亚洲国产aa | 久草精品免费 | 992tv在线观看视频 | 美女爱爱网站 | 2017狠狠拍狠狠狠色 | 亚洲孕妇一级毛片 | 日日日日日日日 | 99久热re在线精彩视频 | 空姐一级毛片 | 精品久久久久久中文字幕2017 | 国产精品九 | 国产黄色片在线免费观看 | 久久之久 | 亚洲成人福利在线观看 | 国产麻豆一区二区三区四区 | 99久久国产综合精麻豆 | 九色pron| 日韩精品一二三区 | 青青青青青国产费线在线观看 | 久草av一区 | 久久久久久九九九 | 国产一区二区三区四 | a级片免费播放 | 亚洲天堂欧美 | 久久久久久久久久久久中文字幕 | 亚洲中文日产2021 | 亚洲AV色男人的天堂 | 国产成在线观看免费视频 | 老司机亚洲精品影院无码 | 亚洲最大成人影院 |