Thursday, March 12, 2009

/* Programmer’s name: Julie Ann Pabio
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 BSIT enrollee

//declaring a constructor

class Queue{

public int entrynum;

public String firstname;

public String lastname;

public char middlename;

public Queue next;

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

{

entrynum=Enum;

firstname=Fname;

lastname=Lname;

middlename=M;

}

//displaying the elements on the list

public void displayQueue()

{

System.out.print(entrynum +” “ + firstname +” “ +” “middlename+ “ “ +: + lastname)

}

}

/*a separate class which contains the methods of the data structure Queue implemented in a linked list*/

class QueueList

private Queue first;

private Queue last;

public QueueList()

{

first=null;

last=null;

}

//checking if the list has elements or not

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 (Enum);

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(001, “Marjorie”, “Egot” , ‘T’, )

theQueue.enqueue(002, “Chrisdyll”, “Pellejo”, ‘P’)

System.out.println(theQueue);

theQueue.enqueue(003, “Julie”, “Pabio”, ‘L’)

System.out.println(theQueue)

theQueue.dequeue(001);

System.out.println(theQueue);

System.out.println(theQueue);

}

}