0% found this document useful (0 votes)
23 views10 pages

Include

Uploaded by

Alapan Pradhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views10 pages

Include

Uploaded by

Alapan Pradhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

SOME OPERATIONS ON SINGLE CIRCULAR LINKED LIST

#include<stdio.h>

#include<stdlib.h>

void create();

void display();

void insert_beg();

void insert_end();

void insert_pos();

void delete_beg();

void delete_end();

void delete_pos();

void search();

typedef struct node

{ int data;

struct node *next;

} sn;

sn *head=NULL;

int main()

int ch;

while(1)

printf("\n________________________________\n");

printf("single circular linked list\n 1. create\n 2. display\n 3. insert at beginning\n 4. insert

at end\n 5. insert at position\n 6. delete at beginning\n 7. delete at end\n 8. delete

at position\n 9. search\n 10. exit\n");

printf("________________________________\n");

printf("enter you choice >>>");

scanf("%d",&ch);

switch(ch)

case 1:

create();

break;

case 2:

display();

break;
case 3:

insert_beg();

break;

case 4:

insert_end();

break;

case 5:

insert_pos();

break;

case 6:

delete_beg();

break;

case 7:

delete_end();

break;

case 8:

delete_pos();

break;

case 9:

search();

break;

case 10:

exit(0);

break;

default:

printf("\n!!! wrong choice !!!");

break;

void create()

sn *s,*p;

s = (sn*)malloc(sizeof(sn));

if(s == NULL)

printf("\nout of memory");
return;

printf("\nenter the data value >>> ");

scanf("%d",&s->data);

s->next=NULL;

if (head==NULL)

head = s;

s->next = head;

else

p = head;

while(p->next != head)

p = p->next;

p->next = s;

s->next = head;

void display()

sn *p;

if (head == NULL)

printf("\nlist is empty");

return;

else

p = head;

printf("\nthe list elements are >> ");

do

printf("\t%d", p->data);

p = p->next;

} while (p != head);
}

void search()

sn *p;

int item,i=1;

if (head == NULL)

printf("\nlist is empty");

return;

else

p=head;

printf("\nenter the data to find >> ");

scanf("%d",&item);

while(p!= NULL)

if(p->data == item)

printf("\nthe value %d is found at %d", item,i);

return;

p = p->next;

i++;

printf("\nthe value %d is not found ", item);

void insert_beg()

sn *s, *p;

s = (sn *)malloc(sizeof(sn));

if (s == NULL)

printf("\nout of memory");

return;
}

printf("\nenter the data value >>> ");

scanf("%d", &s->data);

s->next = NULL;

if (head == NULL)

head = s;

head->next = head;

else

p = head;

while (p->next != head)

p = p->next;

p->next = s;

s->next = head;

head = s;

void insert_end()

sn *s, *p;

s = (sn *)malloc(sizeof(sn));

if (s == NULL)

printf("\nout of memory");

return;

printf("\nenter the data value >>> ");

scanf("%d", &s->data);

s->next = NULL;

if (head == NULL)

head = s;

head->next = head;
}

else

p = head;

while (p->next != head)

p = p->next;

p->next = s;

s->next = head;

void insert_pos()

sn *s,*p;

int i,pos;

s = (sn*)malloc(sizeof(sn));

if(s == NULL)

printf("\nout of memory");

return;

printf("\nenter the position to insert >>> ");

scanf("%d",&pos);

printf("\nenter the data value >>> ");

scanf("%d",&s->data);

s->next = NULL;

if(pos==1)

s->next=head;

head = s;

else

for(i=1,p=head;i<pos-1;i++)

p=p->next;
if(p==NULL)

printf("position not found");

return;

s->next=p->next;

p->next= s;

void delete_beg()

sn *p;

if (head == NULL)

printf("\nlist is empty");

return;

else

p=head;

head=head->next;

printf("\nthe deleted value is %d >>> ",p->data);

free(p);

void delete_end()

sn *s,*p;

if (head == NULL)

printf("\nlist is empty");

return;

else if (head->next== NULL)

{
p=head;

head=NULL;

printf("\nthe deleted value is %d >>> ",p->data);

free(p);

else

p=head;

while(p->next!=head)

s=p;

p=p->next;

s->next= head;

printf("\nthe deleted value is %d >>> ",p->data);

free(p);

void delete_pos()

sn *s, *p;

int i, pos;

if (head == NULL)

printf("\nlist is empty");

return;

else

printf("\nenter the position to delete >>> ");

scanf("%d", &pos);

if (pos == 1)

p = head;

if (head->next == head)

head = NULL;

else

head = head->next;
p->next = NULL;

printf("\nthe deleted value is %d >>> ", p->data);

free(p);

else

p = head;

for (i = 1; i < pos; i++)

s = p;

p = p->next;

if (p == head)

printf("\nposition not found !!!");

return;

s->next = p->next;

printf("\nthe deleted value is %d >>> ", p->data);

free(p);

}
Output :

________________________________

Single circular linked list

1. create

2. display

3. insert at beginning

4. insert at end

5. insert at position

6. delete at beginning

7. delete at end

8. delete at position

9. search

10. exit

________________________________

enter you choice >>> 1

enter the data value >>> 4

________________________________

enter you choice >>>1

enter the data value >>> 3

________________________________

enter you choice >>>1

enter the data value >>> 7

________________________________

enter you choice >>>4

enter the data value >>> 9

________________________________

enter you choice >>>2

the list elments are >> 4 3 7 9

________________________________

enter you choice >>>6

the deleted value is 2 >>>

________________________________

enter you choice >>>2

the list elments are >> 3 7 9

________________________________

enter you choice >>>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy