Home > Back-end >  Data structure, to achieve chain table types, I wrote a. H function, and it worked at first, before
Data structure, to achieve chain table types, I wrote a. H function, and it worked at first, before

Time:09-27

# # ifndef __LINK_H__
# define __LINK_H__

# include & lt; stdio.h>
# include & lt; Stdlib. H>


# define OK 1


Typedef struct LNode {//node type
The int data;
Struct LNode * next;
Struct LNode * head;
Int len.
} Link, * the List;


Typedef int the Status;


The List CreateList (void);//create a new list
The List ListInsert (List, int, int data);//insert elements in list n a
The List ListAppend (List lp, int data);//list extension to expand
The List ListDelete (List, int);//delete elements in list
The Link * FindElelink (List, int);//returns the node of n a p
Int ListLengh List (lp);//the list length
The Status DestroyList List (lp);//destruction list?
The Status ClearList List (lp);//to empty the list (the first clearance no)
Void PrintList (List lp);//print the whole list



The List CreateList (void) {
The List of p;
p-> The head=(List) malloc (sizeof (Link));

p-> The head - & gt; Next=NULL;
If (p - & gt; The head - & gt; Next==NULL) {
Printf (" succeed ");
}

return p;
}//to create a new list


The Status DestroyList List (lp) {
ClearList (lp);
Free (lp - & gt; The head - & gt; Next);
Free (lp - & gt; The head);
Free (lp);
Printf (" has the clean!" );
return OK;
}//destruction list

The Status ClearList List (lp) {
While (ListDelete (lp, 1));
return OK;
}//empty list

The List ListDelete (List lp, int n) {
The Link * p;
The Link * p1.

P=(List) malloc (sizeof (Link));
P1=(List) malloc (sizeof (Link));

if(! Lp - & gt; The head - & gt; Next) {
Printf (" wrong! Fuck!" );
return 0;
}

P=FindElelink (lp, n - 1);
if(! (p& & p-> Next)) return 0;

P1=p - & gt; next;
p-> Next=p - & gt; Next - & gt; next;

Free (p1);
Return the lp;
}//list to delete an element n

The List ListInsert (List lp, int n, int data) {
The Link * p;
The Link * newp;

P=(List) malloc (sizeof (Link));
Newp=(List) malloc (sizeof (Link));

P=FindElelink (lp, n - 1);
if(! P | |! Newp) {
Printf (" wrong! Fuck!" );
exit(0);
}


Newp - & gt; Next=p - & gt; next;
p-> Next=newp;
Newp - & gt; Data=https://bbs.csdn.net/topics/data;

Return the lp;
}//insert value value n element in the linked list


The List ListAppend (List lp, int data) {
The Link * p;
The Link * newp;

P=(List) malloc (sizeof (Link));
Newp=(List) malloc (sizeof (Link));

if(! P | |! Newp) {
Printf (" wrong! Fuck!" );
exit(0);
}
For (p=lp - & gt; head; p-> Next!=NULL; P=p - & gt; Next);
p-> Next=newp;
Newp - & gt; Next=NULL;
Newp - & gt; Data=https://bbs.csdn.net/topics/data;


Return the lp;
}//value for new data node


The Link * FindElelink (List lp, int n) {
The Link * p;
P=(List) malloc (sizeof (Link));

If (n<0 {
Printf (" wrong!" );
}

P=the lp - & gt; The head - & gt; next;
p-> Len=1;

While (p - & gt; Len & lt; N - 1) {
P=p - & gt; next;
p-> Len=p - & gt; Len + 1;
}

return p;
}//return the number of n nodes before p

Void PrintList (List lp) {
The Link * p;
P=(List) malloc (sizeof (Link));
if(! P) {
Printf (" wrong! Fuck!" );
exit(0);
}
P=the lp - & gt; The head - & gt; next;

while(p !=NULL) {
Printf (" % d ", p - & gt; The data);
P=p - & gt; next;
}

}//returns the value of the list

Int ListLength List (lp) {
The Link * p;
P=(List) malloc (sizeof (Link));

P=the lp - & gt; The head - & gt; next;
Int cont=1;

while(p !=NULL) {
P=p - & gt; next;
Cont++;
}

Return cont.
}//length of list


#endif

CodePudding user response:

No need to worry about the following comments, some of them didn't change comments, predefined that a comment is no problem

CodePudding user response:

Function defined in the header file? In the header file is commonly used in the function declaration
  • Related