Write a C program to implement Queues using Singly Linked Lists.
Hints:
The operations to be performed are
1. Insert Front
2. Delete Rear
3. Display
or
1. Insert Rear
2. Delete Front
3. Display
i solve but there are error:
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
// Structure of each node in SLL
struct node
{
int info;
struct node *link;
};
typedef struct node* NODE;
// Function to create a new node from the free memory...
NODE createNode()
{
NODE temp;
temp=(NODE)malloc(sizeof(struct node));
return temp;
}
// Insert a new node at front of the SLL...
NODE insertFront(NODE first, int item)
{
NODE temp;
temp=createNode();
if(temp==NULL)
{
printf("\n\n Sorry..!!! Cant Insert..Bcz..Memory Allocation Failed..");
return first;
}
temp->info=item;
temp->link=first;
first=temp;
printf("\n\n Success..!! %d is inserted at front of SLL successfully..Proceed",item);
return first;
}
void display(NODE first)
{
NODE temp;
for(temp=first; temp!=NULL; temp=temp->link)
printf("\n\n %d", temp->info);
}
NODE deleteRare(NODE last)
{
NODE temp;
temp=last;
last=last->link;
printf("\n\n %d is deleted from the rare of the list...Proceed.",temp->info);
free(temp);
return last;
}
void main()
{
NODE last,first=NULL;
int i, item;
for(i=0;i<5;i++)
{
printf("\n\n Enter the item to be inserted at front of the list--->");
scanf("%d", &item);
first=insertFront(first, item);
}
printf("\n\n The contents of the list created are:");
display(first);
printf("\n\n Lets delete the item at front of the list..");
last=deleteRare(last);
printf("\n\n The contents of the list after deletion are:");
display(last);
printf("\n \n Press any key to stop...");
getch();
}
please help me i want in night