Thursday, March 12, 2009

Programmer: Niel Jay F. Ehilla.

//declaring a constructor of a list Queue
public 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 Queue
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, “Niel jay”, “Ehilla” , ‘F’, )
theQueue.enqueue(002, “Rico”, “Jesyl”, ‘M’)
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);
}
}

No comments:

Post a Comment