単一チェーンテーブルによる学生管理システム

3756 ワード

この学生管理システムは単一チェーンテーブルによって実現され、この管理システムはチェーンテーブルをよりよく操作するために設計されています.
#include 
#include 
#include 
#include 

struct Node
{
	char name[10];
	int num;
	int age;
	struct Node* next;
};

//        
struct Node* createlist()
{
	struct Node* list = (struct Node*)malloc(sizeof(struct Node));// list        
	list->next = NULL;
	return list;
}


//         
struct Node* createnode(char *newname, int newnum, int newage)
{
	struct Node* node = (struct Node*)malloc(sizeof(struct Node)); //           
	strcpy(node->name, newname); //        
	node->age = newage;
	node->num = newnum;
	node->next = NULL;
	return node;
}

//            
void insertback(struct Node* list, char *newname, int newnum, int newage)
{
	struct Node* newnode = createnode(newname, newnum, newage);
	//     
	struct Node* temp = list;//            
	while (temp->next != NULL) //           
	{
		temp = temp->next;
	}
	newnode->next = NULL;    
	temp->next = newnode;
	
}


//      
//                   ,                   
void deleteinfo(struct Node* list, int num)
{
	struct Node* temp = list;  //              
	struct Node* p = list->next;//         
	while (p->num != num)
	{
		temp = temp->next;
		p = p->next;
	}

	temp->next = p->next;
	free(p);
}

//       
//        
void searchinfo(struct Node* list, char *name)
{
	struct Node* temp = list->next;
	while (strcmp(temp->name, name) != 0)
	{
		if (temp->next == NULL)
		{
			printf("        
"); return; } temp = temp->next; } printf(" :%s
:%d
:%d

", temp->name, temp->num, temp->age); } void print(struct Node* list)// { struct Node* temp = list->next; if (temp == NULL) { printf("
"); } while (temp) { printf(" :%s
:%d
:%d

", temp->name, temp->num, temp->age); temp = temp->next; } } //struct Node* student = createlist(); void menu()// { printf("****************************************
"); printf("* 1、 *
"); printf("* 2、 *
"); printf("* 3、 *
"); printf("* 4、 *
"); printf("* 5、 *
"); printf("****************************************
"); } int choice()// { int choice; printf("
"); scanf("%d", &choice); while (choice < 1 || choice > 5) { printf(" ,
"); scanf("%d", &choice); } return choice; } void work(struct Node* student) { menu(); int a = choice(); switch (a) { case 1: { char name[10] = "0"; int num = 0; int age = 0; printf(" , ,
"); scanf("%s",name); scanf("%d", &num); scanf("%d", &age); insertback(student, name, num, age); }break; case 2: { char searchname[10] = "0"; printf("
"); scanf("%s", searchname); searchinfo(student, searchname); }break; case 3: { print(student); }break; case 4: { int deletenum = 0; printf("
"); scanf("%d", &deletenum); deleteinfo(student, deletenum); }break; case 5: { exit(0); }break; default: printf("
"); break; } } int main() { struct Node* student = createlist(); while (1) { work(student); } system("pause"); return 0; }
何かわからないことがあったり、間違っていることがあったらコメントで指摘してくださいね.