}
Skip to main content
SIMPLE QUEUE
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
void main()
{
struct node *head=NULL,*ptr=NULL,*temp=NULL,*top=NULL,*ptr2,*ptr3,*ptr4=NULL;
int choice,n,i;
clrscr();
printf("enter the size of link list\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
temp=(struct node *)malloc(sizeof(struct node));
temp->next=NULL;
printf("\nenter the data in temp variable");
scanf("%d",&temp->data);
if(head==NULL)
{
head=temp;
top=temp;
}
else
{
temp->next=top;
top=temp;
head=top;
} }
ptr3=head;
ptr4=new node;
ptr4->data=45;
ptr4->next=NULL;
ptr4->next=top;
head=ptr4;
ptr3=head;
while(ptr3!=NULL)
{
printf("%d ",ptr3->data);
ptr3=ptr3->next;
}
getch();
}