Linked List:
# Include < String . H >
# Include < Stdlib. h >
# Include < Stdio. h >
Typedef Struct Stu_listme stu_list;
/* Define struct */
Struct Stu_listme
{
Char * P_ch_data;
Stu_list * P_stu_next;
};
Char * Getform_list (stu_list * Phead, Int Nlim)
/* Obtain the K-Bit Data */
{
Char * P_ch_lim = NULL;
Int N_count = 1 ;
Stu_list * P_stu_point = Phead;
While (N_count <= Nlim)
{
If (P_stu_point = Null)
Return NULL;
P_stu_point = P_stu_point -> P_stu_next;
N_count ++ ;
}
If (P_stu_point ! = Null)
{
P_ch_lim = P_stu_point -> P_ch_data;
}
Return P_ch_lim;
}
Int Calu_list (stu_list * Phead)
/* Calculate the length of a linked list */
{
Int N_back = 0 ;
Stu_list * P_stu_point = Phead;
While (P_stu_point -> P_stu_next ! = Null)
{
P_stu_point = P_stu_point -> P_stu_next;
N_back ++ ;
}
Return N_back;
}
Void Insert_node ( Char * Pnow, stu_list ** Phead)
/* Insert linked list */
{
Stu_list * P_stu_me = (Stu_list * ) Malloc ( Sizeof (Stu_list ));
P_stu_me -> P_ch_data = ( Char * ) Malloc (strlen (pnow) + 1 );
Memcpy (p_stu_me -> P_ch_data, pnow, strlen (pnow ));
P_stu_me -> P_ch_data [strlen (pnow)] = ' \ 0 ' ;
If ( * Phead = Null)
{
P_stu_me -> P_stu_next = NULL;
}
Else
{
P_stu_me -> P_stu_next = * Phead;
}
* Phead = P_stu_me;
}
Void List_free (stu_list * Phead)
/* Release linked list */
{
Stu_list * P_stu_me = Phead;
While (P_stu_me ! = Null)
{
Stu_list * P_stu_point = P_stu_me -> P_stu_next;
Free (p_stu_me -> P_ch_data );
Free (p_stu_me );
P_stu_me = P_stu_point;
}
}
Int Main ()
{
Stu_list * P_stu_head = NULL;
Insert_node ( " Fuck " , & P_stu_head );
Insert_node ( " Ffsf " , & P_stu_head );
Printf ( " % S \ n " , Getform_list (p_stu_head, 0 ));
Printf ( " % D \ n " , Calu_list (p_stu_head ));
List_free (p_stu_head );
Return 0 ;
}