A linked list of learning cheats in C Language
The work just turned out is a bit low-level, but it is expected to play a role:
# Include <stdio. h>
# Include <stdlib. h>
# Include <time. h>
# Include <windows. h>
# Define SLEEP () asm (& quot; sleep & quot ;)
Struct student * head;
Struct student
{
Int;
Int B;
Struct student * next;
};
Int n;
Void add ()
{
Printf ("enter two numbers to store \ n ");
Struct student * p1, * p2;
P1 = p2 = (struct student *) malloc (sizeof (struct student ));
Head-> next = p1;
Scanf_s ("% d", & p2-> a, & p2-> B );
While (p2->! = NULL)
{
N = n + 1;
P1-> next = p2;
P1 = p2;
P2 = (struct student *) malloc (sizeof (struct student ));
Scanf_s ("% d", & p2-> a, & p2-> B );
}
P1-> next = NULL;
}
Void print (struct student * head)
{
If (head-> next! = NULL)
{
Struct student * p1;
P1 = (struct student *) malloc (sizeof (struct student ));
P1 = head-> next;
While (p1! = NULL)
{
Printf ("% d \ t % d \ n", p1-> a, p1-> B );
P1 = p1-> next;
}
}
Else printf ("cannot be executed !!! ");
}
Void look ()
{
If (head-> next! = NULL)
{
Struct student * p1;
P1 = (struct student *) malloc (sizeof (struct student ));
P1 = head-> next;
Int m = 1;
Printf ("Enter the location you want to find \ n ");
Int;
Scanf_s ("% d", & );
While (m! =)
{
M = m + 1;
P1 = p1-> next;
}
Printf ("% d \ t % d \ n", p1-> a, p1-> B );
}
Else printf ("cannot be executed !!! ");
}
Void gai ()
{
If (head-> next! = NULL)
{
Struct student * p1;
P1 = (struct student *) malloc (sizeof (struct student ));
P1 = head-> next;
Int m = 1;
Printf ("Enter the location you want to modify \ n ");
Int;
Scanf_s ("% d", & );
While (m! =)
{
M = m + 1;
P1 = p1-> next;
}
Scanf_s ("% d", & p1-> a, & p1-> B );
}
Else printf ("cannot be executed !!! ");
}
Void shan ()
{
If (head-> next! = NULL)
{
Struct student * p1;
P1 = (struct student *) malloc (sizeof (struct student ));
P1 = head;
Int m = 1;
Printf ("Enter the location you want to delete \ n ");
Int;
Scanf_s ("% d", & );
While (m! =)
{
M = m + 1;
P1 = p1-> next;
}
P1-> next = p1-> next;
}
Else printf ("cannot be executed !!! ");
}
Void zeng () /*************************************** **************************************** *****/
{
If (head-> next! = NULL)
{Struct student * p1, * p2, * p3;
P1 = (struct student *) malloc (sizeof (struct student ));
P1 = head-> next;
While (p1-> next! = NULL)
{
Printf ("% d \ t % d \ n", p1-> a, p1-> B );
P1 = p1-> next;
}
Printf ("Enter the data you want to store \ n ");
P2 = p3 = (struct student *) malloc (sizeof (struct student ));
P1-> next = p2;
Scanf_s ("% d", & p3-> a, & p3-> B );
While (p3->! = 0)
{
N = n + 1;
P2-> next = p3;
P2 = p3;
P3 = (struct student *) malloc (sizeof (struct student ));
Scanf_s ("% d", & p3-> a, & p3-> B );
}
P2-> next = NULL;
}
Else printf ("cannot be executed !!! ");
}
Int main () /*************************************** **************************************** ************/
{
Head = (struct student *) malloc (sizeof (struct student ));
Head-> next = NULL;
N = 0;
Int a = 1;
Printf ("************************************* **************************************** * ********************************* \ n ");
Printf ("* <Press 1 for input> <press 2 for output> * \ n ");
Printf ("* <add, press 3> <Delete, Press 4> * \ n ");
Printf ("* <modify by 5> <exit by 0> * \ n ");
Printf ("select the next feature \ n ");
While (! = 0)
{
Scanf_s ("% d", & );
Switch ()
{
Case 0: break;
Case 1: add (); break;
Case 2: print (head); break;
Case 3: zeng (); break;
Case 4: shan (); break;
Case 5: gai (); break;
Default: printf ("do not play !!! "), Sleep (1000), system (" cls "), printf (" Dad will always love you !! \ N ");
}
If (! = 0 ){
Printf ("select the next feature \ n ");
}
}
Printf ("two minutes to be surprised !!!! \ N ");
Sleep (20000 );
Printf ("Let you wait. You're stupid !!! Sb \ n ");
Return 0;
}