0% found this document useful (0 votes)
2 views13 pages

Queue Implementations

The document contains a C program that implements a singly linked list with functionalities to create a list, insert a node at the beginning, and delete a node at the end. It includes functions for menu display, node creation, counting nodes, and displaying the list contents. The main function runs an infinite loop to handle user input and perform the corresponding operations on the linked list.

Uploaded by

25x51a3276
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)
2 views13 pages

Queue Implementations

The document contains a C program that implements a singly linked list with functionalities to create a list, insert a node at the beginning, and delete a node at the end. It includes functions for menu display, node creation, counting nodes, and displaying the list contents. The main function runs an infinite loop to handle user input and perform the corresponding operations on the linked list.

Uploaded by

25x51a3276
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

#include<stdio.

h>

#include<stdlib.h>

struct slinklist

int data;

struct slinklist *next;

};

typedef struct slinklist node;

node *start=NULL;

int menu()

int ch;

printf("\n [Link] the list");

printf("\n 2. insert a node at beginning");

printf("\n 3. delete a node at end");

scanf("%d",&ch);

return ch;

node *getnode()

node *newnode;

newnode=(node*)malloc(sizeof(node));

printf("enter the data");

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

newnode->next=NULL;

return newnode;

int countnode(node*ptr)

int count=0;
while(ptr!=NULL)

count++;

ptr=ptr->next;

return count;

void creatlist(int n)

int i;

node *newnode;

node *temp;

for(i=0;i<n;i++)

newnode=getnode();

if(start==NULL)

start=newnode;

else

temp=start;

while(temp->next!=NULL)

temp=temp->next;

temp->next=newnode;

void display()

node *temp;
temp=start;

printf("\n the contents of the list");

if(start==NULL)

printf("list is empty");

else

while(temp!=NULL)

printf("%d->",temp->data);

temp=temp->next;

void insert_at_beg()

node *newnode;

newnode=getnode();

if(start==NULL)

start=newnode;

else

newnode->next=start;

start=newnode;

void delete_at_last()

node *temp,*prev;

if(start==NULL)
printf("\n empty list");

else{

temp=start;

prev=start;

while(temp->next!=NULL)

prev=temp;

temp=temp->next;

void main()

int ch,n;

while(1)

ch=menu();switch(ch);

case1:if(start==NULL)

printf("node you can creat");

scanf("%d",&n);

creatlist(n);

printf("list created");

else

printf("\n list is created");

break;

case2: insert_at_beg();
break;

case3: delete_at_last();

break;

Output:- #include<stdio.h>

#include<stdlib.h>

struct slinklist

int data;

struct slinklist *next;

};

typedef struct slinklist node;

node *start=NULL;

int menu()

int ch;

printf("\n [Link] the list");

printf("\n 2. insert a node at beginning");

printf("\n 3. delete a node at end");

scanf("%d",&ch);

return ch;

node *getnode()

node *newnode;

newnode=(node*)malloc(sizeof(node));

printf("enter the data");

scanf("%d",&newnode->data);
newnode->next=NULL;

return newnode;

int countnode(node*ptr)

int count=0;

while(ptr!=NULL)

count++;

ptr=ptr->next;

return count;

void creatlist(int n)

int i;

node *newnode;

node *temp;

for(i=0;i<n;i++)

newnode=getnode();

if(start==NULL)

start=newnode;

else

temp=start;

while(temp->next!=NULL)

temp=temp->next;

temp->next=newnode;

}
}

void display()

node *temp;

temp=start;

printf("\n the contents of the list");

if(start==NULL)

printf("list is empty");

else

while(temp!=NULL)

printf("%d->",temp->data);

temp=temp->next;

void insert_at_beg()

node *newnode;

newnode=getnode();

if(start==NULL)

start=newnode;

else

newnode->next=start;

start=newnode;
}

void delete_at_last()

node *temp,*prev;

if(start==NULL)

printf("\n empty list");

else{

temp=start;

prev=start;

while(temp->next!=NULL)

prev=temp;

temp=temp->next;

void main()

int ch,n;

while(1)

ch=menu();switch(ch);

case1:if(start==NULL)

printf("node you can creat");

scanf("%d",&n);

creatlist(n);
printf("list created");

else

printf("\n list is created");

break;

case2: insert_at_beg();

break;

case3: delete_at_last();

break;

Output:- #include<stdio.h>

#include<stdlib.h>

struct slinklist

int data;

struct slinklist *next;

};

typedef struct slinklist node;

node *start=NULL;

int menu()

int ch;

printf("\n [Link] the list");

printf("\n 2. insert a node at beginning");

printf("\n 3. delete a node at end");

scanf("%d",&ch);

return ch;

}
node *getnode()

node *newnode;

newnode=(node*)malloc(sizeof(node));

printf("enter the data");

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

newnode->next=NULL;

return newnode;

int countnode(node*ptr)

int count=0;

while(ptr!=NULL)

count++;

ptr=ptr->next;

return count;

void creatlist(int n)

int i;

node *newnode;

node *temp;

for(i=0;i<n;i++)

newnode=getnode();

if(start==NULL)

start=newnode;

else
{

temp=start;

while(temp->next!=NULL)

temp=temp->next;

temp->next=newnode;

void display()

node *temp;

temp=start;

printf("\n the contents of the list");

if(start==NULL)

printf("list is empty");

else

while(temp!=NULL)

printf("%d->",temp->data);

temp=temp->next;

void insert_at_beg()

node *newnode;

newnode=getnode();
if(start==NULL)

start=newnode;

else

newnode->next=start;

start=newnode;

void delete_at_last()

node *temp,*prev;

if(start==NULL)

printf("\n empty list");

else{

temp=start;

prev=start;

while(temp->next!=NULL)

prev=temp;

temp=temp->next;

void main()

int ch,n;

while(1)

ch=menu();switch(ch);
{

case1:if(start==NULL)

printf("node you can creat");

scanf("%d",&n);

creatlist(n);

printf("list created");

else

printf("\n list is created");

break;

case2: insert_at_beg();

break;

case3: delete_at_last();

break;

Output:- [Link] the list

2. insert a node at beginning

3. delete a node at end

Input 3

Node you can creat 3

Ether data 55

Enter data 78

Enter data 88

List created.

You might also like