資料結構(順序表)

2021-08-17 12:22:08 字數 1826 閱讀 7926

#include#include#include#include#define ok 1  

#define error 0

#define overflow -2

#define maxsize 100

typedef int status;

typedef struct

student;

typedef student file;

typedef struct

sqlist;

status initlist(sqlist *l) // 構造空的順序表 l

file getelem(sqlist &l,int i) // 訪問順序表,找到 i位置,返回給 e

int search(sqlist &l,char str) // 根據名字查詢,返回該同學在順序表中的編號

return 0;

}

status listinsert(sqlist &l,int i,file e)

l.elem[i]=e;

++l.length;

return ok;

}

status listdelete(sqlist &l,int i)

--l.length;

return ok;

} void input(file *e)

void output(file *e)

void printline(student m,int num)else

}}int main()

l.length=a;

puts("");

break;

case 2:

break;

case 3:

char m[20];

printf("請輸入要查詢的學生姓名:");

scanf("%s",&m);

if(search(l,m))

else

printf("查詢失敗!");

break;

case 4:

printf("請輸入要查詢的位置:");

int ad;

scanf("%d",&ad);

b=getelem(l,ad);

output(&b);

break;

case 5:

printf ("請輸入要插入的位置:");

int ad2;

scanf("%d",&ad2);

printf("請輸入學生資訊:\n");

input(&c);

if(listinsert(l,ad2,c))

else

break;

case 6:

printf("請輸入要刪除的位置:");

int ad3;

scanf("%d",&ad3);

if(listdelete(l,ad3))

else

break;

case 7:

printf("已錄入的學生個數為:%d\n\n",l.length);

break;

case 8:

system("pause");

break;

defult:

printf("輸入有誤,請重新輸入!");

scanf("%d",&choose);

break; } }

}

資料結構 順序表

順序表的特徵 1由唯一的表名標識 2佔據一塊連續的儲存空間 3資料順序存放,元素之間有先後關係 定義動態的順序表 define maxsize 100 typedef struct sqlist 這個結構體型別存放的是順序表的資訊和順序表的資料 初始化順序表 void initsqlist sqli...

資料結構 順序表

順序表示最簡單的乙個資料結構,直接貼 吧,因為比較簡單。include include typedef struct sqlist sqlist void initlist sqlist l l length 0 void getelem sqlist l 初始化 l length j printf...

資料結構順序表

include include include include include include include include include include include include include include using namespace std define maxn 100000...