實現的功能如下:
原始碼:
#include #include #include #include /**定義學生資料物件的結構體**/
struct stu_node;
typedef struct stu_node student; //將結構體別名
/**函式體宣告**/
student* createlist(int n);
void printlist(student* s);
int insertlist(student* s,int i,char name,int score,int n);
int findlist(student* s,char name);
void deletelist(student* s,int j);
void changelist(student* s,int j,char name,int score);
/**建立鍊錶**/
student* createlist(int n)
p->next = null;
printlist(head);
return head;
}/**輸出鍊錶**/
void printlist(student* s)
}/**插入元素**/
int insertlist(student* s,int i,char name,int score,int n)else
ne = (student *)malloc(sizeof(student));
strcpy(ne->name,name);
ne->score = score;
ne->next = pre->next;
pre->next = ne;
n++;
} printlist(s);
return n;
}/**按名字查詢結點**/
int findlist(student* s,char name)else
} return -1;
}/**刪除節點**/
void deletelist(student* s,int j)
student *p = pre->next;
pre->next = p->next;
printf("deleted student (%s,%d)\n",p->name,p->score);
free(p);
printlist(s);
}/**改變鍊錶節點**/
void changelist(student* s,int j,char name,int score)
printf("changed student (%s,%d) to (%s,%d)\n",pre->name,pre->score,name,score);
strcpy(pre->name,name);
pre->score = score;
printlist(s);
}void main()
student = createlist(n);
break;
case 2:
printf("input the name of student to change:");
scanf("%s",&old_name);
j =findlist(student,old_name);
if(j==-1)else
break;
case 3:
printf("input the name of student to find:");
scanf("%s",&old_name);
j =findlist(student,old_name);
if(j==-1)else
break;
case 4:
printf("input the name of student to delete:");
scanf("%s",&old_name);
j =findlist(student,old_name);
if(j==-1)else
break;
case 5:
if(n>0)
printlist(student);
else
printf("the list is empty\n");
break;
case 6:
printf("input the student's name\t");
scanf("%s",&name);
printf("input the student's score\t");
scanf("%d",&score);
printf("input the position to insert:");
int p;
scanf("%d",&p);
n = insertlist(student,p,name,score,n);
break;
default:
printf("please choose from the menu!");
break;
} }}
資料結構262 學生資訊管理
某班學生的資訊存放在乙個線性單鏈表中,但每學期都有學生因故退學。現要求根據退學學生的學號,將其資訊從鍊錶中刪除。假設學生的資料只儲存姓名 學號 性別,並採用結構體型別描述。若煉表中有退學學生,輸出刪除該學生後的學生資料 如果鍊錶中沒有該學生,則輸出錯誤資訊no。例1 lidong 1001 m zh...
資料結構262 學生資訊管理
試題名稱 學生資訊管理 時間限制 1 秒 記憶體限制 10000kb 問題描述 某班學生的資訊存放在乙個線性單鏈表中,但每學期都有學生因故退學。現要求根據退學學生的學號,將其資訊從鍊錶中刪除。假設學生的資料只儲存姓名 學號 性別,並採用結構體型別描述。輸入說明 輸入n個學生資料 1 n 10 每行乙...
資料結構練習
include include define size 20 typedef struct list 重新命名結構體 list t 建立 list t creat list int size list length 0 空表初始化,實際長度為0 return list 返回堆區申請的首位址 判空 i...