Chain storage of linear tables

Source: Internet
Author: User

Chain storage of linear tables
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Define N 500010
# Define INF 10000000
# Define LL long
# Define eps 10E-9
# Define mem (a) memset (a, 0, sizeof ())
# Define w (a) while ()
# Define s (a) scanf (% d, &)
# Define ss (a, B) scanf (% d, & a, & B)
# Define sss (a, B, c) scanf (% lld, & a, & B, & c)
# Define maxn9999
# Define MAXSIZE 10
# Define DLEN 4
# Define maxn9999
# Define MAXSIZE 10
# Define DLEN 4
Using namespace std;
Typedef struct node
{
Int data;
Struct node * next;
} Node;
Void create (Node ** p)
{
* P = NULL;
}
Int my_insert (Node ** p, int x)
{
Node * p1;
P1 = (Node *) malloc (sizeof (Node ));
If (p1 = NULL)
Return false;
Node * p2 = * p;
While (p2! = NULL)
{
If (p2-> data = x)
Break;
P2 = p2-> next;
}
P1-> data = x;
P1-> next = * p;
* P = p1;
Return true;
}
Int my_delete (Node ** head, int x)
{
Node * p = * head, * q;
If (p-> data = x) // the header node is the element to be deleted.
{
* Head = (* head)-> next;
Free (p );
Return true;
}
Else
{
Q = p; p = p-> next; // q indicates the forward node, and p points to the next node.
While (p! = NULL)
{
If (p-> data = x)
{
Q-> next = p-> next;
Free (p );
Return true;
}
Q = p; p = p-> next;
}
}
Return false;
}
Int my_find (Node ** head, int x)
{
Node * p = * head;
While (p! = NULL)
{
If (p-> data = x)
Break;
P = p-> next;
}
Return p-> data;
}
Void my_clear (Node ** head)
{
Node * p = * head, * q;
While (p! = NULL)
{
Q = p;
P = p-> next;
Free (q );
}
}
Void my_showalldata (Node ** head)
{
Node * p = * head, * q;
While (p! = NULL)
{
Cout < Data <;
P = p-> next;
}
Cout < }
Int main ()
{
Int x, n;
Node * head;
Create (& head );
Cout < Cin> n;
Cout < > X;
My_insert (& head, x );
}
Cout < My_showalldata (& head );
Cout < Cin> x;
My_delete (& head, x );
My_showalldata (& head );
Cout < Cin> x;
Cout < // My_clear (& head); // formating
Free (head );
Return 0;
}

 

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.