Data structure Linked List learning notes

Source: Internet
Author: User

#include <stdio.h> #include <stdlib.h> #include <string.h>struct stu_node{char num[15]; int score;struct stu_node *next;}; Struct stu_node *stu_create () {struct stu_node *head, *newn, *tail;char num[ 15];int score;printf ("Please enter student's number and score (school number is 0 to end): \ n"), scanf ("%s%d", Num,&score);newn =  (struct  stu_node *) malloc (sizeof (Struct stu_node)); strcpy (newn->num,num); newn->score =  score;newn->next = null;head =newn;tail = newn;while (1) {printf ("Please enter student's number and score ( The number is 0 to end): \ n "), scanf ("%s%d ", Num,&score), if (strcmp (num," 0 ") ==0) break;else{newn =  (struct stu _node *) malloc (sizeof (Struct stu_node)); strcpy (Newn->num,num);newn->next = null; tail->next = newn;tail = newn;}} Return head;} Void stu_print (struct stu_node *head) {struct stu_node *p = head;if (P==NULL) {printf ("LearnRaw information is empty: "); return;} printf ("\t\n"), while (P!=null)  {printf ("%s\t%d\n", P->num,p->score);p =p->next;}} Void stu_modify (struct stu_node *head) {char num[15];struct stu_node *p=head;if ( Head==null) {printf ("Student Information is empty:"); return;} printf ("Please enter the student number to be modified:"); scanf ("%s", num); while (P!=NULL&NBSP;&AMP;&AMP;&NBSP;STRCMP (p->num, num)!=0) p=p- >next;if (p!=null)  {printf ("Please enter the student's score to be modified") scanf ("%d", &p->score)  ;} elseprintf ("The student who did not find the school number!"); struct stu_node *stu_delete  (struct stu_node *head) {Char num[15];struct stu _node *p=head, *p1;if (p==null) {printf ("Student Information is empty:"), return head; }printf ("Please enter the student number to delete:"); scanf ("%s", num), while (P!=NULL&NBSP;&AMP;&AMP;&NBSP;STRCMP (p->num,num)!=0) {P1=p;p=p->next;} if (p!=null) {if (p=head) Head=p->next;elsep1->next = p->next;free (p)  ;} elseprintf ("The student who has not found the school number!") \ n "); return head;} Void main () {INT&NBSP;CHOICE;STRUCT&NBSP;STU_NODE&NBSP;*HEAD&Nbsp;=null;printf ("Welcome to Student information Management system \ n");p rintf ("\ t-------------------------------------------\ n");p rintf ("\ T1. Create Student Information link List   2. Show student information \ n ");p rintf (" \t3. Modify student information       4. Delete Student information \ n ");p rintf ( "\t5. Exit student information \ n")  ;p rintf ("\ t-------------------------------------------\ n"); while (1) {printf ("\t  Please select the function module, enter the number 1-5: "), scanf ("%d ", &choice)  ;switch (choice) {case 1: head = stu_create ( ); Break;case 2: stu_print (head); Break;case 3: stu_modify (head);break;case 4:  Head = stu_delete (head); break;case 5: exit (0);d efault: printf ("Input Error! \ n ")  ;}}}


Data structure Linked List learning notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.