Home > Back-end >  The linear table do students address book
The linear table do students address book

Time:05-11

# include
# include
# include
# include
Typedef struct
{
Char num [5].
char name[20];
Char phone [10].
} studata;
Typedef struct node
{
Studata data;
struct node *next;
} listnode, * linklist;
Void menu ()
{
Printf (" \ n * * * * * * * * * * * * * * * * * * * * * * * * * * * class address book * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n \ n ");
Printf (" 2-1 - build directory to view all records 3 - query 4 - classmates join from 0 to 5 - classmates quit system \ n \ n ");
Printf (" please select (0 to 5) : ");
} linklist creatlist ()
{linklist head, s, p, q;
char ch; Head=(listnode *) malloc (sizeof (listnode));
if(! The head) exit (1);
The head - & gt; Next=NULL;
P=the head;
Do {
S=(linklist) malloc (sizeof (listnode));
if(! S) exit (1);
Printf (" please enter students number: ");
The scanf (" % s ", s - & gt; Data. The num);
Printf (" please enter the classmate's name: ");
The scanf (" % s ", s - & gt; Data. The name);
Printf (" please input the classmate's phone number: "); The scanf (" % s ", s - & gt; Data. The phone);
S - & gt; Next=p - & gt; Next;
P - & gt; Next=s;
Printf (" \ n continue to add? (y/n) ");
The scanf (" c "\ n %, & amp; Ch);
} while (ch=='y' | | ch=='y');
Return the head;
}
Listnode * searchlist (linklist head)
{listnode * p;
int x;
Char num [5].
char name[20];
Printf (" 1. According to the number query 2. According to the name query \ n ");
Printf (" please select: ");
The scanf (" % d ", & amp; X);
If (x==1)
{printf (" please enter thesis& students number: ");
The scanf (" % s ", num);
For (p=head; p!=NULL& & STRCMP (p - & gt; Data. The num, num)!=0; P=p - & gt; Next); }
Else if (x==2)
{
Printf (" please enter the thesis& schoolmate's name: ");
The scanf (" % s ", name);
For (p=head; p!=NULL& & STRCMP (p - & gt; Data. The name, the name)!=0; P=p - & gt; Next);
}
Return the p;
}
Void insertlist (linklist head, listnode * p)
{p - & gt; Next=head - & gt; Next; The head - & gt; Next=p; }
Void delnode (linklist head)
{linklist p, q; char ch; P=searchlist (head);
if(! P)
{
Printf (" could not find qualified record! \n");
return ;
}
Printf (" sure you want to delete? (y/n) ");
The scanf (" c "\ n %, & amp; Ch);
If (ch=='n' | | ch=='n')
return;
For (q=head; Q!=NULL& & Q - & gt; Next!=p; Q=q - & gt; Next); Q - & gt; Next=p - & gt; Next;
free(p);
Printf (" deleted successfully! \n");
}
Void printlist (linklist head)
{linklist p; P=the head - & gt; Next; Printf (" \ n number name and telephone number "); while(p!=NULL)
{printf (" % s \ n % s % s ", p - & gt; Data. The num, p - & gt; Data. The name, p - & gt; Data. The phone); P=p - & gt; Next;
}}
Int main ()
{int t; Linklist head, p;
The menu ();
While (1)
{
The scanf (" % d ", & amp; T);
The switch (t)
{case 1:
Printf (" build directory \ n ");
The head=creatlist ();
break;
Case 2:
Printf (" to view all records \ n ");
Printlist (head);
break;
Case 3:
Printf (" query \ n ");
P=searchlist (head);
If (p)
{printf (" \ n number name and telephone number ");
Printf (" % s \ n % s % s ", p - & gt; Data. The num, p - & gt; Data. The name, p - & gt; Data. The phone); } the else printf (" this person cannot be found! \n");
break;
Case 4:
Printf (" insert \ n ");
P=(listnode *) malloc (sizeof (listnode));
Printf (" please enter students number: ");
The scanf (" % s ", p - & gt; Data. The num);
Printf (" please enter the classmate's name: ");
The scanf (" % s ", p - & gt; Data. The name);
Printf (" please input the classmate's phone number: "); The scanf (" % s ", p - & gt; Data. The phone);
Insertlist (head, p);
break;
Case 5:
Printf (" delete \ n ");
Delnode (head);
break;
Case 0:
Printf (" exit \ n ");
return 0;
}
}
}
The great god help me to comment the appreciate
Or can improve it

CodePudding user response:

Modified as follows, for your reference:
 # include 
# include
# include
# include
Typedef struct
{
Char num [5].
char name[20];
Char phone [10].
} studata;

Typedef struct node
{
Studata data;
Struct node * next;
} listnode, * linklist;

Void menu ()
{
Printf (" \ n * * * * * * * * * * * * * * * * * * * * * * * * * * * class address book * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n \ n ");
Printf (" 2-1 - build directory to view all records 3 - query 4 - classmates join from 0 to 5 - classmates quit system \ n \ n ");
Printf (" please select (0 to 5) : ");
}

Linklist creatlist ()
{
Linklist head, s, p, q;
char ch;
Head=(listnode *) malloc (sizeof (listnode));
if(! The head) exit (1);
The head - & gt; Next=NULL;
P=the head;
Do {
S=(linklist) malloc (sizeof (listnode));
if(! S) exit (1);
Printf (" please enter students number: ");
The fflush (stdout); The rewind (stdin);
The scanf (" % s ", s - & gt; Data. The num);
Printf (" please enter the classmate's name: ");
The fflush (stdout); The rewind (stdin);
The scanf (" % s ", s - & gt; Data. The name);
Printf (" please input the classmate's phone number: ");
The fflush (stdout); The rewind (stdin);
The scanf (" % s ", s - & gt; Data. The phone);
S - & gt; Next=p - & gt; Next;
P - & gt; Next=s;
Printf (" \ n continue to add? (y/n) ");
The fflush (stdout); The rewind (stdin);
The scanf (" % c ", & amp; Ch);
} while (ch=='y' | | ch=='y');
Return the head;
}

Listnode * searchlist (linklist head)
{
Listnode * p;
int x;
Char num [5].
char name[20];
If (head==NULL) {
Printf (" no record, please add a record! \n");
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related