This is my first blog post on csdn. This is my virgin post ~~~~
//List.h
# Ifndef list_h_included # define list_h_included /// the knowledge about typedef is not very well understood. Please strengthen it !! Typedef struct node; typedef struct node * ptrtonode;/*********** this linked list is different from the general implementation here, hiding pointers, that is, typedef ptrtonode list; the general definition is typedef struct node {int data; struct node * Next;} List; if so, the initialization function must use a second-level pointer, void listinitia (list ** list); ***************************/typedef ptrtonode list; typedef ptrtonode position; typedef int datatype; struct node {datatype data; position next;}; void listinitia (list * List); int listinsert (list, int index, datatype X ); void listprint (list); void listdel (list * List); # endif // list_h_included// List. CPP # include <stdlib. h> # include <stdio. h> # include "list. H "/*************** note void listinitia (list * List) */void listinitia (list * List) {* List = (list) malloc (sizeof (node); (* List)-> DATA = 100; (* List)-> next = NULL;} int listinsert (list, int index, datatype X) {list tmplist = List; If (index <0) return 0; int I = 0; while (tmplist-> next! = NULL) & (index! = I) {I ++; tmplist = tmplist-> next;} List newlist = (list) malloc (sizeof (node); newlist-> DATA = X; newlist-> next = NULL; tmplist-> next = newlist; return 1;} void listprint (list) {list tmplist = List; while (tmplist-> next) {tmplist = tmplist-> next; printf ("% d \ t", tmplist-> data) ;}// is the implementation correct? Is there a memory leak ?? Void listdel (list * List) {list tmplist = * List; List TMP; while (! Tmplist-> next) {TMP = tmplist; tmplist = tmplist-> next; free (TMP );}}// Test File
# Include <stdio. h> # include <stdlib. h> # include "list. H "int main () {list = NULL; // list is a pointer listinitia (& list); int I; for (I = 0; I <10; I ++) listinsert (list, I, I + 10); listprint (list); listdel (& list); Return 0 ;}I personally wrote the above. I don't know if there are any errors. If so, please point out .....