경 과 구 . 구 고 구. 걸 ...
¶
{{|
그
-
-student 구 (dept, name, num(1~20)
-기(
그
-
-student 구 (dept, name, num(1~20)
-기(
( -num ...,
(-binary search??, sequential search...)
(option- 고 )
|}}(-binary search??, sequential search...)
(option- 고 )
¶
~cpp /* 그 * ->->->NULL */ #include <stdio.h> #define HEAD 0 #define TAIL 1 #define ORIGINALSEARCH 0 #define DELETIONSEARCH 1 struct Student{ char dept[10]; char name[10]; int number; struct Student* nextStudent; }; typedef struct Student Student; int Menu(int aPopulation);// int Process(int aMenu, int aPopulation, Student* aListPointer[]); int AddStudent(int aPopulation, Student* aListPointer[]);// void SearchStudent(Student* aHead);// 기 int DelStudent(int aPopulation, Student* aListPointer[]);// 기 void InputStudentInfo(Student* aStudent);// void FreeMemory(Student* aHead);// void ListOutput(Student* aHead);// Student* Searching(int aNumber, Student* aHead, int aType);//기 int main() { Student* listPointer[2];// 꼬 int population = 0;// do{ population = Process(Menu(population), population, listPointer); printf("\n");//기 게 . }while(population != -1);//그 FreeMemory(listPointer[HEAD]);// system("PAUSE"); return 0; } int Menu(int aPopulation){ int selectedMenu; printf("☞. 그.\n"); printf("1. \n"); if(aPopulation){// printf("2. \n"); printf("3. \n"); } printf("4. \n"); printf("\n : "); scanf("%d", &selectedMenu); return selectedMenu; } int Process(int aMenu, int aPopulation, Student* aListPointer[]){ if(aMenu == 1)// aPopulation = AddStudent(aPopulation, aListPointer); else if(aMenu == 4)// aPopulation = -1; else if(aPopulation){// if(aMenu == 2)//기 SearchStudent(aListPointer[HEAD]); if(aMenu == 3)// aPopulation = DelStudent(aPopulation, aListPointer); } else printf("\n .\n"); return aPopulation; } int AddStudent(int aPopulation, Student* aListPointer[]){ Student* newStudent; newStudent = (Student*)malloc(sizeof(Student)); InputStudentInfo(newStudent); if(!aPopulation){// 경 aListPointer[HEAD] = newStudent; } else{ aListPointer[TAIL]->nextStudent = newStudent; } aListPointer[TAIL] = newStudent; aPopulation++; printf("\n \n");// . ListOutput(aListPointer[HEAD]); return aPopulation; } void SearchStudent(Student* aHead){ int searchNumber; Student* searched; printf("\n : "); scanf("%d", &searchNumber); searched = Searching(searchNumber, aHead, ORIGINALSEARCH); if(searched) printf(" 공!\n: %s\n: %s\n: %d\n", searched->dept, searched->name, searched->number); else printf(" , .\n"); } int DelStudent(int aPopulation, Student* aListPointer[]){ int deleteNumber; Student* searchedFormer; Student* searched; printf("\n : "); scanf("%d", &deleteNumber); searchedFormer = Searching(deleteNumber, aListPointer[HEAD], DELETIONSEARCH); if(!searchedFormer || searchedFormer->nextStudent){ if(!searchedFormer){ // searched = aListPointer[HEAD]; aListPointer[HEAD] = searched->nextStudent; } else if(!(searched->nextStudent)){// searched = searchedFormer->nextStudent; searchedFormer->nextStudent = NULL; aListPointer[TAIL] = searchedFormer; } else{ //간 searched = searchedFormer->nextStudent; searchedFormer->nextStudent = searched->nextStudent; } free(searched);// aPopulation--; printf("\n \n");// ListOutput(aListPointer[HEAD]); } else printf(" , .\n"); return aPopulation; } void InputStudentInfo(Student* aStudent){ printf(": "); scanf("%s", aStudent->dept); printf(": "); scanf("%s", aStudent->name); printf(": "); scanf("%d", &(aStudent->number)); aStudent->nextStudent = NULL; } void FreeMemory(Student* aHead){ Student* temp; while(aHead){// ~ temp = aHead; free(temp); aHead = aHead->nextStudent; } } void ListOutput(Student* aHead){ int counter = 0; Student* temp; temp = aHead; while(temp){// ~ counter++; printf("%s\n",temp->name); temp = temp->nextStudent; } printf(" %d .\n", counter); } Student* Searching(int aNumber, Student* aHead, int aType){ Student* searched = aHead; Student* searchedFormer = NULL; while(searched){//// ~ if(searched->number == aNumber) break; else{ searchedFormer = searched; searched = searched->nextStudent; } } if(aType == ORIGINALSEARCH) return searched; else return searchedFormer; }