Simple operation of the C language----------linked list

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.