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;
}