Saturday, March 28, 2009

My references in different kinds of sorting:

  1. bubble sort: http://en.wikipedia.org/wiki/Bubble_sort
  2. insertion sort: http://en.wikipedia.org/wiki/Insertionsort
  3. shell sort: http://en.wikipedia.org/wiki/Shell_sort
  4. heap sort: http://en.wikipedia.org/wiki/Heap_sort
  5. merge sort: http://en.wikipedia.org/wiki/Merge_sort
  6. quick sort: http://en.wikipedia.org/wiki/Quick_sort
  7. bucket sort: http://en.wikipedia.org/wiki/Bucket_sort

Thursday, March 12, 2009

QUEUE IMPLEMENTATION(group activity)

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

}

}

QUEUES

  • is a particular kind of collection in which the entities in the collection are kept in order and the principal (or only) operations on the collection are the addition of entities to the rear terminal position and removal of entities from the front terminal position.
  • First-In-First-Out (FIFO) data structure,the first element added to the queue will be the first one to be removed.
  • an example of a linear data structure
  • are common in computer programs, where they are implemented as data structures coupled with access routines, as an abstract data structure or in object-oriented languages as classes
  • are dynamic collections which have some concept of order

Method Summary
boolean add(E e)
Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.
E element()
Retrieves, but does not remove, the head of this queue.
boolean offer(E e)
Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
E peek()
Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
E poll()
Retrieves and removes the head of this queue, or returns null if this queue is empty.
E remove()
Retrieves and removes the head of this queue.




references:
http://en.wikipedia.org/wiki/Queue_(data_structure)
http://www.cs.auckland.ac.nz/software/AlgAnim/queues.html
http://java.sun.com/javase/6/docs/api/java/util/Queue.html