?? main2-2.cpp
字號:
// main2-2.cpp 檢驗bo2-2.cpp的主程序(與main2-1.cpp很像)
#include"c1.h"
typedef int ElemType;
#include"c2-2.h" // 與main2-1.cpp不同
#include"bo2-2.cpp" // 與main2-1.cpp不同
Status comp(ElemType c1,ElemType c2)
{ // 數據元素判定函數(相等為TRUE,否則為FALSE)
if(c1==c2)
return TRUE;
else
return FALSE;
}
void visit(ElemType c) // 與main2-1.cpp不同
{
printf("%d ",c);
}
void main() // 除了幾個輸出語句外,主程和main2-1.cpp很像
{
LinkList L; // 與main2-1.cpp不同
ElemType e,e0;
Status i;
int j,k;
i=InitList(L);
for(j=1;j<=5;j++)
i=ListInsert(L,1,j);
printf("在L的表頭依次插入1~5后:L=");
ListTraverse(L,visit); // 依次對元素調用visit(),輸出元素的值
i=ListEmpty(L);
printf("L是否空:i=%d(1:是 0:否)\n",i);
i=ClearList(L);
printf("清空L后:L=");
ListTraverse(L,visit);
i=ListEmpty(L);
printf("L是否空:i=%d(1:是 0:否)\n",i);
for(j=1;j<=10;j++)
ListInsert(L,j,j);
printf("在L的表尾依次插入1~10后:L=");
ListTraverse(L,visit);
GetElem(L,5,e);
printf("第5個元素的值為:%d\n",e);
for(j=0;j<=1;j++)
{
k=LocateElem(L,j,comp);
if(k)
printf("第%d個元素的值為%d\n",k,j);
else
printf("沒有值為%d的元素\n",j);
}
for(j=1;j<=2;j++) // 測試頭兩個數據
{
GetElem(L,j,e0); // 把第j個數據賦給e0
i=PriorElem(L,e0,e); // 求e0的前驅
if(i==INFEASIBLE)
printf("元素%d無前驅\n",e0);
else
printf("元素%d的前驅為:%d\n",e0,e);
}
for(j=ListLength(L)-1;j<=ListLength(L);j++)//最后兩個數據
{
GetElem(L,j,e0); // 把第j個數據賦給e0
i=NextElem(L,e0,e); // 求e0的后繼
if(i==INFEASIBLE)
printf("元素%d無后繼\n",e0);
else
printf("元素%d的后繼為:%d\n",e0,e);
}
k=ListLength(L); // k為表長
for(j=k+1;j>=k;j--)
{
i=ListDelete(L,j,e); // 刪除第j個數據
if(i==ERROR)
printf("刪除第%d個數據失敗\n",j);
else
printf("刪除的元素為:%d\n",e);
}
printf("依次輸出L的元素:");
ListTraverse(L,visit);
DestroyList(L);
printf("銷毀L后:L=%u\n",L);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -