Page 175 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 175
Fundamentals of Data Structures
Notes cqptr = front = rear = NULL;
printf (“Enter 1 for addition and 2 to delete element from the queue”)
printf(“Enter your choice”)
scanf(“%d”,&choice);
switch (choice)
{
case 1 :
printf (“Enter the element to be added :”);
scanf(“%d”,&x);
add(&q,x);
break;
case 2 :
delete();
break;
}
}
/************ Add element ******************/
add(int value)
{
struct cq *new;
new = (struct cq*)malloc(sizeof(queue));
new->value = value
new->next = NULL;
if (front == NULL)
{
cqptr = new;
front = rear = queueptr;
}
else
{
rear->next = new;
rear=new;
}
}
/* *************** delete element ***********/
delete()
{
int delvalue = 0;
if (front == NULL)
{ printf(“Queue is empty”);
delvalue = front->value;
168 LOVELY PROFESSIONAL UNIVERSITY