Queue Adt using Array it has the header file qarry.h It contains structure queue create queue Make empty, Dequeue function with appropriate function and variable. Data structure Lab Source code Programming algorithm - CS1152 c/c++
“qarray.h” file Source code Queue adt using Array
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<stdlib.h>
struct Queue
{
int capacity;
int size;
int front;
int rear;
int *array;
};
typedef struct Queue *PtrToNode;
typedef PtrToNode QUEUE;
QUEUE CreateQueue(int max)
{
QUEUE Q;
Q=(struct Queue*)malloc(sizeof(struct Queue));
if(Q==NULL)
printf("\nFatal error");
else
{
Q->size=0;
Q->capacity=max;
Q->front=0;
Q->rear=-1;
Q->array=(int*)malloc(sizeof(int)*max);
if(Q->array==NULL)
printf("\nFatal error");
else
printf("\nQueue is created successfully");
}
return Q;
}
void MakeEmpty(QUEUE Q)
{
Q->size=0;
Q->front=0;
Q->rear=-1;
}
int IsEmpty(QUEUE Q)
{
return Q->size==0;
}
int IsFull(QUEUE Q)
{
return Q->size==Q->capacity;
}
void EnQueue(int x,QUEUE Q)
{
if(IsFull(Q))
printf("\nQueue is Full");
else
{
Q->rear++;
Q->array[Q->rear]=x;
Q->size++;
}
}
void DeQueue(QUEUE Q)
{
if(IsEmpty(Q))
printf("\nQueue is empty");
else
{
Q->front++;
Q->size--;
}
}
int Front(QUEUE Q)
{
return Q->array[Q->front];
}
QUEUE DisposeQueue(QUEUE Q)
{
MakeEmpty(Q);
free(Q->array);
free(Q);
Q=NULL;
return Q;
}
void Display(QUEUE Q)
{
int i;
for(i=Q->front;i<=Q->rear;i++)
printf("\n%d",Q->array[i]);
}
“qarray.c” file Queue adt using Array
#include<stdio.h>
#include"qarray.h"
void main()
{
QUEUE Q=NULL;
int a,size,ch;
printf("\n\n1.CreateQueue\n 2.Enqueue\n 3.Dequeue\n 4.Front\n 5.MakeEmpty\n 6.IsEmpty\n 7.IsFull\n 8.DisposeQueue\n 9.Display\n 10.Exit\n");
X:
printf("\nEnter ur choice:\t");
scanf("%d",&ch);
switch(ch)
{
case 1:
if(Q==NULL)
{
printf("\nEnter the size of queue");
scanf("%d",&size);
Q=CreateQueue(size);
}
else
printf("\nQueue is already created");
break;
case 2:
if(Q==NULL)
printf("\nQueue is not yet created");
else
{
printf("\nEnter the element to insert");
scanf("%d",&a);
EnQueue(a,Q);
}
break;
case 3:
if(Q==NULL)
printf("\nQueue is not yet created");
else
DeQueue(Q);
break;
case 4:
if(Q==NULL)
printf("\nQueue is not yet created");
else
{
a=Front(Q);
printf("\n Front element present in the queue is:\t%d",a);
}
break;
case 5:
if(Q==NULL)
printf("\n Queue is not yet created");
else
{
MakeEmpty(Q);
printf("\n Now Queue becomes empty");
}
break;
case 6:
if(Q==NULL)
printf("\n Queue is not yet created");
else if(IsEmpty(Q))
printf("\n Queue is empty");
else
printf("\n Queue contains some element");
break;
case 7:
if(Q==NULL)
printf("\n Queue is not yet created");
else if(IsFull(Q))
printf("\n Queue is full");
else
printf("\n Queue is not full");
break;
case 8:
if(Q==NULL)
printf("\n Queue is not yet created");
else
{
Q=DisposeQueue(Q);
printf("\n Queue is disposed");
}
break;
case 9:
if(Q==NULL)
printf("\n Queue is not yet created");
else
{
printf("\n The elements in the Queue are:");
Display(Q);
}
break;
case 10:
exit(0);
default:
printf("\n*******WRONG CHOICE********");
}
goto X;
}
OUTPUT Queue adt using Array Data Structure Lap programming algorithm
1.CreateQueue
2.Enqueue
3.Dequeue
4.Front
5.MakeEmpty
6.IsEmpty
7.ISFull
8.DisposeQueue
9.Display
10.Exit
Enter ur choice: 1
Enter the size of queue: 3
Queue is created successfully
Enter ur choice: 2
Enter the element to insert: 100
Enter ur choice: 2
Enter the element to insert: 200
Enter ur choice: 2
Enter the element to insert: 300
Enter ur choice: 2
Enter the element to insert: 400
Queue is Full
Enter ur choice: 6
Queue contains some element
Enter ur choice: 4
Front element present in the queue is: 100
Enter ur choice: 7
Queue is Full
Enter ur choice: 9
The Elements in the queue are:
100
200
300
Enter ur choice: 3
Enter ur choice: 9
The Elements in the queue are:
200
300
Enter ur choice: 7
Queue is not Full
Enter ur choice: 4
Front element present in the queue is: 200
Enter ur choice: 5
Now Queue becomes empty
Enter ur choice: 8
Queue is Disposed
Enter ur choice: 12
***********WRONG ENTRY********
Enter ur choice: 10
Data structure Lab Source code Programming algorithm - CS1152 c/c++
Monday, May 17, 2010
Implementation Of Queue Adt Using Array Data Structure Lab program
Subscribe to:
Post Comments (Atom)
Labels
3D-2D Translation
Algorithms
Batch Programming
C language
C world
C++
DBMS
Ebook
Games
JAVA
Java Programs
JNTU MATERIALS
JNTU PREVIOUS QUESTION PAPERS
JNTU SYLLABUS BOOKS
LAB MANUALS
Linux
Mobile softwares
Networking
Online Programs
PC TIPS
Software Diagrams
Software Engineering
Softwares
System Software
Visual Basic
7 comments:
I really like looking through an article that will make people think.
Also, thank you for allowing me to comment!
Here is my web page : drunk teens
I've been surfing on-line more than three hours nowadays, but I never discovered any attention-grabbing article like yours. It's beautiful value
sufficient for me. In my opinion, if all site owners and bloggers made just right content material
as you did, the internet will probably be a lot more
helpful than ever before.
My web site: Young teen fucked hard - Videos
I was recommended this blog by means of my cousin. I am now not positive whether this put up is written
through him as nobody else recognise such special approximately my problem.
You're wonderful! Thank you!
My web site - Indigo Augustine DP
whoah this blog is great i like studying your articles. Stay
up the good work! You realize, many persons are hunting round for this information,
you can help them greatly.
my webpage: hookah lounge Orlando
Do you mind if I quote a couple of your posts as long
as I provide credit and sources back to your blog?
My website is in the very same niche as yours and my users would certainly benefit from a lot of the information you present here.
Please let me know if this alright with you.
Appreciate it!
My website > contractors in Orlando fl
When someone writes an post he/she maintains the plan of a user
in his/her mind that how a user can understand it. So
that's why this piece of writing is perfect. Thanks!
Also visit my blog post; www.porn-index.net
When I initially left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I receive 4 emails with the same comment.
Perhaps there is a way you are able to remove me from
that service? Appreciate it!
my web blog - assfucked.org
Post a Comment