Here is a list of a single linked list of the basic algorithm of the integrated program, two-way linked lists and cycle list of integrated procedures you can try it on their own.
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define N-typedef struct NODE
{
Char name[20];
struct node *link;
}stud;
Stud * creat (int n)
{
Stud *p,*h,*s;
int i;
if ((h= (Stud *) malloc (sizeof (stud))) ==null)
{
printf ("Cannot allocate memory space!");
Exit (0);
}
H->name[0]= ' ";
h->link=null;
P=h;
for (i=0;i<n;i++)
{
if ((s= (Stud *) malloc (sizeof (stud))) ==null)
{
printf ("Cannot allocate memory space!");
Exit (0);
}
p->link=s;
printf ("Please enter the name of%d person", i+1);
scanf ("%s", s->name);
s->link=null;
P=s;
}
return (h);
}
Stud * Search (stud *h,char *x)
{
Stud *p;
Char *y;
p=h->link;
while (P!=null)
{
y=p->name;
if (strcmp (y,x) ==0)
return (p);
else p=p->link;
}
if (p==null)
printf ("No find this data!");
}
Stud * SEARCH2 (stud *h,char *x)
{
Stud *p,*s;
Char *y;
p=h->link;
S=h;
while (P!=null)
{
y=p->name;
if (strcmp (y,x) ==0)
return (s);
Else
{
p=p->link;
s=s->link;
}
}
if (p==null)
printf ("No find this data!");
}
void Insert (stud *p)
{
Char stuname[20];
Stud *s;
if ((s= (Stud *) malloc (sizeof (stud))) ==null)
{
printf ("Cannot allocate memory space!");
Exit (0);
}
printf ("Please enter the name of the person you want to insert:");
scanf ("%s", stuname);
strcpy (S->name,stuname);
s->link=p->link;
p->link=s;
}
void del (stud *x,stud *y)
{
Stud *s;
S=y;
x->link=y->link;
Free (s);
}
void print (Stud *h)
{
Stud *p;
p=h->link;
printf ("Data information is: \ n");
while (P!=null)
{
printf ("%s", &* (P->name));
p=p->link;
}
}
void Quit ()
{
Exit (0);
}
void menu (void)
{
CLRSCR ();
printf ("\t\t\t single linked list C language implementation instance \ n");
printf ("\t\t| ———————————————— |\n");
printf ("\t\t| |\n");
printf ("\t\t| [1] Establishment of a new table |\n ");
printf ("\t\t| [2] Find Data |\n ");
printf ("\t\t| [3] Inserting Data |\n ");
printf ("\t\t| [4] Delete data |\n ");
printf ("\t\t| [5] Print Data |\n ");
printf ("\t\t| [6] Exit |\n ");
printf ("\t\t| |\n");
printf ("\t\t| If not set up a new table, please set up first! |\n ");
printf ("\t\t| |\n");
printf ("\t\t| ———————————————— |\n");
printf ("\t\t Please enter your option (1-6):");
}
Main ()
{
int choose;
Stud *head,*searchpoint,*forepoint;
Char fullname[20];
while (1)
{
menu ();
scanf ("%d", &choose);
Switch (choose)
{
Case 1:head=creat (N);
Break
Case 2:printf ("Enter the name of the person you are looking for:");
scanf ("%s", FullName);
Searchpoint=search (Head,fullname);
printf ("The name of the person you are looking for is:%s", *&searchpoint->name);
printf (\ n Press ENTER to return to the main menu.) ");
GetChar (); GetChar ();
Break
Case 3:printf ("Enter the person you want to insert behind:");
scanf ("%s", FullName);
Searchpoint=search (Head,fullname);
printf ("The name of the person you are looking for is:%s", *&searchpoint->name);
Insert (Searchpoint);
Print (head);
printf (\ n Press ENTER to return to the main menu.) ");
GetChar (); GetChar ();
Break
Case 4:print (head);
printf ("Enter the name of the person you want to delete:");
scanf ("%s", FullName);
Searchpoint=search (Head,fullname);
FOREPOINT=SEARCH2 (Head,fullname);
Del (forepoint,searchpoint);
Break
Case 5:print (head);
printf (\ n Press ENTER to return to the main menu.) ");
GetChar (); GetChar ();
Break
Case 6:quit ();
Break
DEFAULT:PRINTF ("you entered an illegal character!) press ENTER to return to the main menu. ");
CLRSCR ();
menu ();
GetChar ();
}
}
}
Finish