Coder Social home page Coder Social logo

circular-linked-list's Introduction

circular-linked-list

code for circular linked list

#include<stdio.h> #include<stdlib.h>

struct clist { int info; struct clist* next;

}; struct clist *start=NULL;

void add(int item) { struct clist ptr1,ptr2; if (start==NULL) { start=(struct clist )malloc(sizeof(struct clist)); start->info=item; start->next=start; } else { ptr1=start; while(ptr1->next!=NULL) { ptr1=ptr1->next; } ptr2= (struct clist)malloc(sizeof(struct clist)); ptr1->next=ptr2; ptr2->next=start; ptr2->info=item;

}

}

int delete() { int item=0; struct clist *ptr1,*ptr2; ptr1=start; start=ptr1->next; while(ptr2!=NULL) { ptr2=ptr2->next; } free(ptr1);

return item;

}

void show() { struct clist*ptr1; ptr1=start; printf("START->"); while (ptr1!=NULL) { printf("%d->", ptr1->info); ptr1=ptr1->next; } printf("NULL"); }

void main() { int op,val; do { printf("\nDouble linked operations"); printf("\n1. ADD "); printf("\n2. Delete"); printf("\n3. SHOW"); printf("\n0. EXIT"); printf("\nEnter the choice : "); scanf("%d",&op); if(op==0) break; else if(op==1) { printf("Enter the number to be inserted : "); scanf("%d",&val); add(val); printf("Added \n"); } else if(op==2) { val=delete(); printf("Item deleted=%d", val); }

    else if(op==3)
    {
        show();
    }

}while(1);

}

circular-linked-list's People

Contributors

shivika011 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.