C Data Structure-linear table (chain table)

Source: Internet
Author: User
# Include <stdio. h> # Include <Stdlib. h> # Define Maxlength 1000 Struct  Linknode {  Int  Date;  Struct Linknode * Link;}; typedef  Struct  Linknode; linknode * Createlinknode (){  Int  I; linknode * Node, * P ,*_ Temp; Node = (Linknode *) malloc ( Sizeof  (Linknode ));  If (! Node) {printf (  "  Memory Allocation failed  "  ); Exit (  1  );} Puts (  "  Enter a value  "  ); Scanf (  " % D  " , & Node-> Date); Node -> Link = NULL; _ temp = Node;  For (I = 1 ; I < 3 ; I ++ ) {P = (Linknode *) malloc ( Sizeof  (Linknode ));  If (! P) {puts ( "  Memory Allocation failed  "  ); Exit (  1  );} Puts (  "  Enter a value  "  ); Scanf (  "  % D  " , & P-> Date); P -> Link = NULL; _ temp -> Link =P; _ temp = _ Temp-> Link ;}  Return  Node;} linknode * Findnode (linknode * head, Int  Num) {linknode * P = Head;  While  (P ){  If (P-> date = num) Return  P; P = P-> Link ;} Return  P ;}  Void Shownode (linknode * P ){  While (P! = Null) {printf (  "  % D \ t  " , P-> Date); P = P-> Link ;}}  Void Insertnode (linknode * P, Int  Val) {linknode * Newnode = (linknode *) malloc ( Sizeof  (Linknode); newnode -> Date = Val; newnode -> Link = NULL;  If (P-> link = NULL) P-> link = Newnode;  Else  {Newnode -> Link = p-> Link; P -> Link = Newnode ;}  Return  ;}  Void Deletenode (linknode * head, linknode * P) {linknode * _ Temp;  If (P-> link! = Null) {_ temp = Head;  While (_ Temp-> link! = Null ){  If (_ Temp-> link = P) {_ temp -> Link = p-> Link;  Break  ;} _ Temp = _ Temp-> Link ;}} free (P );  Return  ;}  Void Freenode (linknode * Head) {linknode * PTR;  While (Head! = Null) {PTR = Head; head = Head-> Link; free (PTR );}}  Void  Main (){  Int Sear, sear1; linknode * Newhead ,* PTR; newhead = Createlinknode (); shownode (newhead); printf (  "  Enter the value to be searched  "  ); Scanf (  "  % D  " ,& SEAR); PTR = Findnode (newhead, sear );  If (! PTR) {printf ( "  No value found  "  );}  Else  {Puts (  "  Enter the data to insert  "  ); Scanf (  "  % D  " ,& SEAR); insertnode (PTR, sear); shownode (newhead);} puts (  "  Enter the data to be searched and deleted "  ); Scanf (  "  % D  " ,& Sear1); PTR = Findnode (newhead, sear1 );  If (! PTR) {puts (  "  This value is not found  "  );}  Else  {Deletenode (newhead, PTR); shownode (newhead );}} 

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.