Thursday, March 12, 2009

Implementation of QUEUE

/* Programmer’s name: Matet P. Tipudan 
Name of Program: Queue implementation
Date Started: March 13, 2009
Date Finished : March 13, 2009
Instructor : Mr. Dony Dongiapon
Course: IT 123: Data Structures
Objective: To be able to make a program that we can implement a queue data structure in a linked list.
*/


Concept: List of employees in a given company

//class constructor
class Queue{
public int employeenum;
public String firstname;
public String Lastname;
public char Middlename;
public Queue next;


public Queue (int Enum, String Fname, String Lname, char M; )
{

emlopyeenum=Enum;
firstname=Fname;
lastname=Lname;
middlename=M;
}


//displaying the elements on the list
public void displayQueue()
{
System.out.print(employeename +” “ + firstname +” “ +” “+middlename+ “ “ +: + lastname)
}
}


/*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 Enum, String Fname, String Lname, char M,)

{
Queue newQueue= new Queue (int Enum, String Fname, String Lname, char M,)

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


//deleting an element on the queue
public void Dequeue (int Enum)
{
Queue newQueue=new Queue (int Enum, String Fname, String Lname, char M)

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, “Nemilyn”, “Bayacag”, ‘M’ )

theQueue.enqueue(2, “Lovely”, “Bajar”, ‘C’ );
System.out.println(theQueue);

theQueue.enqueue(3,“Nellen”, “Ortiz”, ‘C’ )
System.out.println(theQueue)



theQueue.dequeue(3);

System.out.println(theQueue);



System.out.println(theQueue);
}
}

No comments:

Post a Comment