Created
October 7, 2016 16:37
-
-
Save rashedcs/a5db0ba163e1c23d17b26f6be5a10b43 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
using namespace std; | |
struct node | |
{ | |
int data; | |
node *next; | |
}; | |
node *front = NULL; | |
node *rear =NULL; | |
node *creation(int data) | |
{ | |
node *tmp=(struct node *)malloc(sizeof(struct node)); | |
tmp->data = data; | |
tmp->next=NULL; | |
return tmp; | |
} | |
void insertion(int item) | |
{ | |
node *newnode = creation(item); | |
if(front==NULL) | |
{ | |
front = rear = newnode; | |
} | |
else | |
{ | |
rear->next = newnode; | |
rear = newnode; | |
} | |
} | |
void deletion() | |
{ | |
struct node *temp; | |
if (front == NULL) | |
{ | |
printf("\nQueue is Empty \n"); | |
return; | |
} | |
else | |
{ | |
temp = front; | |
front = front->next; | |
if(front == NULL) rear = NULL; | |
free(temp); | |
} | |
} | |
void display() | |
{ | |
node *temp=front; | |
if(front == NULL) | |
{ | |
printf("Queue is Overflow\n"); | |
} | |
else | |
{ | |
printf("Queue is :\n"); | |
while(temp != NULL) | |
{ | |
printf("%d ",temp->data); | |
temp = temp->next; | |
} | |
} | |
printf("\n"); | |
} | |
int main() | |
{ | |
int choice, item; | |
while(1) | |
{ | |
printf("1.Insert\n"); | |
printf("2.Delete\n"); | |
printf("3.Display\n"); | |
printf("4.Quit\n"); | |
printf("Enter your choice : "); | |
scanf("%d", &choice); | |
if(choice==1) | |
{ | |
scanf("%d", &item); | |
insertion(item); | |
} | |
else if(choice==2) deletion(); | |
else if(choice==3) display(); | |
else printf("Wrong type \n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment