C 언어 데이터 구조 학생 관리 시스템

25300 단어
  1 #include
  2 #include
  3 #include<string.h>
  4 
  5 
  6 
  7 struct student{
  8     char name [20];
  9     char num[10];
 10     int age ;
 11 
 12 };
 13 
 14 struct Node{
 15     struct student data;
 16     struct Node *next;
 17 };
 18 
 19 //       
 20 struct Node* createList(struct student data){
 21     struct Node* newNode =(struct Node*)malloc(sizeof(struct Node));
 22     newNode->data= data;
 23     newNode->next= NULL;
 24     return newNode ;
 25         
 26 }
 27 
 28 //    ,     :     
 29 void insertNodeByHead(struct Node* listHeadNode,struct student data){
 30     struct Node* newNode;
 31     newNode->next=listHeadNode->next; 
 32     listHeadNode->next=newNode;
 33 
 34 }
 35 
 36 //   
 37 void deleteNodeByAppoinName(struct Node* listHeadNode,char * name){
 38     struct Node* posFrontNode = listHeadNode;
 39     struct Node* posNode = listHeadNode->next;
 40     if(posNode==NULL){
 41         printf("     
"); 42 return; 43 }else{ 44 while(strcmp(posNode->data.name,name)){ 45 posFrontNode =posNode; 46 posNode =posFrontNode->next; 47 if(posNode==NULL){ 48 printf("
"); 49 return; 50 } 51 } 52 posFrontNode->next= posNode->next; 53 free(posNode); 54 } 55 } 56 57 // 58 struct Node* searchNodeByAppoinNum(struct Node* listHeadNode,char*num){ 59 struct Node* pMove =listHeadNode->next; 60 if(pMove==NULL) 61 return pMove; 62 else{ 63 while(strcmp(pMove->data.num,num)){ 64 pMove = pMove->next; 65 if(pMove=NULL) 66 break; 67 } 68 return pMove; 69 } 70 } 71 72 // 73 void printNode(struct Node* curNode){ 74 printf(" \t \t \t"); 75 printf("%s\t%s\t%d\t
",curNode->data.name,curNode->data.num,curNode->data.age); 76 } 77 78 // 2, 79 void printList(struct Node*listHeadNode){ 80 struct Node* pMove = listHeadNode->next; 81 printf(" \t \t \t"); 82 while(pMove){ 83 printf("%s\t%s\t%d\t
",pMove->data.name,pMove->data.num,pMove->data.age); 84 pMove = pMove->next; 85 } 86 printf("
"); 87 } 88 89 void systemMenu(){ 90 // 91 printf("============================================
"); 92 printf("\t
"); 93 printf("\t0.
"); 94 printf("\t1.
"); 95 printf("\t2.
"); 96 printf("\t3.
"); 97 printf("\t4.
"); 98 printf("\t5.
"); 99 printf("============================================
"); 100 printf(" 0~5
"); 101 } 102 void keyDown(){ 103 struct Node*list =NULL; 104 int useKey; 105 struct student tempData; 106 scanf("%d",&useKey); 107 switch(useKey){ 108 case 0: 109 printf("\t[ ]
"); 110 system("pause"); 111 exit(0); 112 break; 113 case 1: 114 printf("\t[ ]
"); 115 printf(" , , "); 116 scanf("%s%s%d",tempData.name,tempData.num,&tempData.age); 117 insertNodeByHead(list,tempData); 118 break; 119 case 2: 120 printf("\t[ ]
"); 121 printList(list); 122 break; 123 case 3: 124 printf("\t[ ]
"); 125 printf(" "); 126 scanf("%s",tempData.name); 127 deleteNodeByAppoinName(list,tempData.name); 128 break; 129 case 4: 130 printf("\t[ ]
"); 131 printf(" "); 132 scanf("%s",tempData.num); 133 if(searchNodeByAppoinNum(list,tempData.num)==NULL){ 134 printf(" "); 135 } 136 else{ 137 printf(" : , , "); 138 } 139 break; 140 case 5: 141 printf("\t[ ]
"); 142 printf(" :"); 143 scanf("%s",tempData.num); 144 if(searchNodeByAppoinNum(list,tempData.num)==NULL){ 145 printf(" "); 146 } 147 else{ 148 printNode(searchNodeByAppoinNum(list,tempData.num)); 149 } 150 break; 151 default: 152 printf(" , 0~5"); 153 } 154 } 155 int main (){ 156 157 while(1){ 158 systemMenu(); 159 keyDown(); 160 system("pause"); 161 system("cls"); 162 } 163 return 0; 164 }

좋은 웹페이지 즐겨찾기