Professional Documents
Culture Documents
Isamis Niversity: College of Computer Studies
Isamis Niversity: College of Computer Studies
Isamis Niversity: College of Computer Studies
ACTIVITY 07
IMPLEMENTING QUEUES
LEARNING OUTCOME:
1. Use the basic operations of a Queue data structure.
INSTRUCTIONS:
This is a collaborative activity. The partner(s) that you have in the Midterm Laboratory Exam will be
your partner in this activity. Only one program output will be uploaded per partner(s) but each must
submit an individual answer to follow-up questions.
Study the given program implementing the basic operations of a stack data structure in C program.
Retype the codes but using the Java program syntax and semantics. Run the program and inspect the
outputs.
The given program which will be used as basis for the modifications and enhancements of codes is
given below.
#include<stdio.h>
#include<conio.h>
#define MAX 5
void insert(int);
int del();
int queue[MAX], rear=0, front=0;
void display();
int main()
{
char ch , a='y';
int choice, token;
printf("1.Insert");
printf("\n2.Delete");
printf("\n3.show or display");
do
{
printf("\nEnter your choice for the operation: ");
scanf("%d",&choice);
switch(choice)
{
case 1: insert(token);
display();
break;
1
Misamis University
Ozamiz City 7200
ACTIVITY 07
IMPLEMENTING QUEUES
case 2:
token=del();
printf("\nThe token deleted is %d",token);
display();
break;
case 3:
display();
break;
default:
printf("Wrong choice");
break;
}
printf("\nDo you want to continue(y/n):");
ch=getch();
}
while(ch=='y'||ch=='Y');
getch();
return 0;
}
void display()
{
int i;
printf("\nThe queue elements are:");
for(i=rear;i<front;i++)
{
printf("%d ",queue[i]);
}
}
2
Misamis University
Ozamiz City 7200
ACTIVITY 07
IMPLEMENTING QUEUES
do
{
printf("\nEnter the token to be inserted:");
scanf("%d",&token);
queue[front]=token;
front=front+1;
printf("do you want to continue insertion Y/N");
a=getch();
}
while(a=='y');
}
int del()
{
int t;
if(front==rear)
{
printf("\nQueue empty");
return 0;
}
rear=rear+1;
t=queue[rear-1];
return t;
}
3
Misamis University
Ozamiz City 7200
ACTIVITY 07
IMPLEMENTING QUEUES
Variables Variables are Some variable Poor use of Variables used are
named names are variable or incorrect
appropriately and inappropriate or inappropriate use
used efficiently variables are over- of variable names
used or under-used
Formatting/ Well-organized Disorganized tabs Poor use of tabs No use of tabs and
Readability and easy to follow and spaces or it and white space white spaces
through allows readability and is very
appropriate use of by someone who difficult to read
tabbing and white knows what is
spaces supposed to be
doing
Documentation Contains required Header and Comments are too Comments are
heading with comments are general missing
program inappropriate or
description and comments are
appropriate use of poorly described
comments