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

Write a C program...

I don't go to a java website asking for c++ help. Why do you come to a c++ forum asking for C help.

I just don't understand why this is such a common occurance.

*moved

sorry>>>>>there are noooooooooooooooo one help us in this website

please >>>................................

Could you explain your logic for deleteRear as the argument passed to it looks like NULL and if it was passed correct last node it's next pointer would be NULL, so how you are updating the second last node which actualy is needed?

Of course after this helper function works, you must do the actual en/dequeue functions(actually insertFront ie enqueue you have already, if it is properly tested to work in all cases.)

What is the exact issue that you are facing ?

FYI if you use google you will find lots of examples of linked list code all over internet

your code segment for deleteRear is probably flawed.
you must traverse upto the node preceding the node to be deleted i.e

NODE temp = start;*/the top of the link list should be stored in a global vaiable since this is a single link link-list*/
while( temp->link!= last )
{
   temp = temp->next;
}
temp->next = last->next; /* assign end pointer to the preceding node*/
free(last);

@zaraki

Your loop is missing a condition. What if the node to be deleted is not present in the linked list ?
This problem is usually solved by returning from the function when temp->link == NULL

hmm right. didn't think abt that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.