#include <stdio.h>#include<malloc.h>typedefstructnode{//Defining node Types CharData//data fields structNode *next;//pointer Field}linklist;linklist* Create () {//Create a linked list Charkey; Linklist*phead;//Head PointerLinklist *pnew;//new NodeLinklist *pend;//Tail HandsPhead = (linklist*)malloc(sizeof(linklist)); Pend=Phead; Puts ("Please enter the linked list you want to create to $ end"); Key=GetChar (); while(key!='$') {pnew= (linklist*)malloc(sizeof(linklist)); Pnew->data =key; Pend->next = pnew;//new node inserts footerPend=pnew;//The tail pointer points to the new footerkey=GetChar (); } pend->next = NULL;//set the next node that the tail node points to to be empty returnPhead;//returns the head pointer}linklist* Get (linklist* phead,intPOS) {//Find the node of POS intCur =0;//Scanning DeviceLinklist *p; P= Phead;//point to head node while((P->next!=null) && (Cur<pos)) {//illegal or exiting at the tailp = p->Next; Cur++; } if(cur==POS) { returnp; }Else{ returnNULL; }}voidPrint (linklist *phead) {//Print linked listlinklist *p = phead->Next; while(p!=NULL) {printf ("%c",p->data); P=p->Next; } puts ("");}intMainvoid) {linklist* Phead =Create (); Print (Phead); intPOS; Puts ("Please enter the location you want to find"); scanf ("%d",&POS); Linklist* Pfind =Get (Phead,pos); if(Pfind! =NULL) printf ("%c",pfind->data); Elseputs ("input Error!"); return 0;}
Simple operation of the C language----------linked list