Thursday, March 12, 2009

QUEUE IMPLEMENTATION

Thursday, March 12, 2009


/* Programmer’s name: Ortiz, Nellen
Name of Program: Queue implementation
Date Started: March 9, 2009
Date Finished : March 12, 2009
Instructor : Mr. Dony Dongiapon
Course: IT 123: Data Structures
Objective: To be able to make a program that implements a queue data structure in a linked list */



Concept: List of Courses Offered in the College

//class constructor
class Queue{
public int coursenum;
public String coursename;
public int unitnum;
public String deptname;
public Queue next;


public Queue (int Cnum, String Cname, int Unum, String Dname; )
{

coursenum=Cnum;
coursename=Cname;
unitnum=Unum;
deptname=Dname;
}


//displaying the elements on the list
public void displayQueue()
{
System.out.print(coursenum +” “ + deptname +” “ +” “+unitnum+ “ “ +: + coursename)
}
}


/*a separate class which contains the ,methods that would be used in implementing the program */
class QueueList
private Queue first;
private Queue last;
public QueueList()
{
first=null;
last=null;
}


//checking if the queue has elements
public Boolean isEmpty()
{
return (first==null);
}

//inserting an element on the queue
public void Enqueue(int Cnum, String Cname, int Unum, String Dname; )

{
Queue newQueue= new Queue (int Cnum, String Cname, int Unum, String Dname )

if( isEmpty())
last = newQueue;
newQueue.next=first;
first=newQueue;
}


//deleting an element on the queue
public void Dequeue (int Cnum)
{
Queue newQueue=new Queue (int Cnum, String Cname, int Unum, String Dname )

int temp=first.entrynum;
if (first.next==null)
last=null;
first=first.next;
return temp


}
}


public class MainClass {
public static void main(String[] args) {
LinkQueue theQueue = new LinkQueue();
theQueue.enqueue(1, “BSIT”, 118, “ICSD” )

theQueue.enqueue(2, “BSN”, 368, “ND”);
System.out.println(theQueue);

theQueue.dequeue(2);

System.out.println(theQueue);



System.out.println(theQueue);
}

No comments:

Post a Comment