最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C語言使用鏈表實現(xiàn)學生信息管理系統(tǒng)

 更新時間:2019年12月27日 10:18:38   作者:Newtol  
這篇文章主要為大家詳細介紹了C語言使用鏈表實現(xiàn)學生信息管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C語言實現(xiàn)學生信息管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

代碼實現(xiàn)的功能:

1.插入學生信息 2.顯示學生信息 3.刪除學生信息 4.在指定位置插入學生信息 5.查找學生信息

代碼內(nèi)容:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define Max_Student_Num 10
#define Max_Str_len 20

typedef struct T_student{
 int number;
 char name [Max_Student_Num];
 char phone[Max_Student_Num];
};

typedef struct T_Node{
 struct T_student s;
 struct T_Node * next;
};

char command_str[]={"\n1 display all member;\n2 insert member;\n3 del member;\n4 exit\nCommand selection:"};

struct T_student students[Max_Student_Num];
struct T_Node * head = NULL;

int main(int argc, char* argv[])
{
 int command, i;
 struct T_student student;
 struct T_Node * pStu =head;
 memset(&student,0,sizeof(student));

 while(1){
  printf("%s",command_str);
  scanf("%d", &command);
  switch(command)
  {
  case 1:
   if(head==NULL){
    printf("empty!!!!!!!!!!!!\n");
    break;
   }
   if(head->next==head){
    display_student(head);
   }else{
    pStu=head->next;
    do
    {
     display_student(pStu);
     pStu=pStu->next;
    }while(pStu!= head->next);
//
   }

   break;
  case 2:
   printf("enter new student number:");
   scanf("%d", &student.number);
   printf("enter new student name:");
   scanf("%s", &student.name);
   if(strlen(student.name) > Max_Str_len)
   {
    printf("name is too long!!\n");
    continue;
   }

   printf("enter new student phone:");
   scanf("%s", &student.phone);

   if(strlen(student.phone) > Max_Str_len)
   {
    printf("phone is too long!!\n");
    continue;
   }

   printf("\n");

   if(student.number != 0)
     insert_student(student);

   break;
  case 3:
   printf("Inter deleted student number:");
   scanf("%d", &student.number);
   del_student(student);
   break;
  case 4:
   return 0;
  default:
   printf("error command, try again\n");
   break;
  }
 }
}


void display_student( struct T_Node * pStu){
 printf("number:%d name:%s phone:%s \n",pStu->s.number,pStu->s.name,pStu->s.phone);
}

void insert_student(struct T_student student){

 struct T_Node* pNode ;
 struct T_Node* pStu =NULL;
 int size = sizeof(struct T_Node);
 pStu=(struct T_Node *)malloc (size);
 if(pStu == NULL){
  return ;
 }
 memcpy(&pStu->s,&student,sizeof(student));

 if(head==NULL){

   pStu->next=head;
   head=pStu;
   head->next=head;
   return ;
 }
 pStu->next = head->next;
 head->next=pStu;


}

void del_student(struct T_student student){
 struct T_Node *pNode =NULL,*p=NULL;
 if(head->next==head && head->s.number==student.number){
  pNode=head;
  head=NULL;
  free(pNode);
  printf("success");
  return;
 }
 for(pNode=head->next;pNode != head;pNode=pNode->next){
  if( pNode->next->s.number == student.number){
   p=pNode->next->next;

   free(pNode->next);
   pNode->next=p;

   printf("Delete success!\n");
   return;
  }

 }
 printf("Not Found\n");
}

測試截圖:

1.插入功能:

2.顯示功能:

3.查詢功能:

4.刪除功能:

5.指定位置插入:

更多學習資料請關注專題《管理系統(tǒng)開發(fā)》。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

电白县| 都江堰市| 合阳县| 浦北县| 涞源县| 新河县| 家居| 班戈县| 双峰县| 周至县| 乌鲁木齐县| 宁蒗| 磐石市| 泾川县| 泽普县| 崇文区| 阿拉善盟| 凉山| 潞城市| 东莞市| 石门县| 五峰| 和田县| 万载县| 普格县| 土默特左旗| 米脂县| 冷水江市| 长春市| 胶南市| 鄯善县| 民和| 铜川市| 长宁区| 株洲市| 东明县| 准格尔旗| 阳谷县| 台前县| 恩平市| 郴州市|