Tuesday, February 24, 2009

1.) Definition: Queues are dynamic collections which have some concept of order. It is the in order of entries in the queue. It emphasizes the FIFO or known as First In, First.


2.)Illustration:











3.)Reference:
http://www.cs.auckland.ac.nz/software/AlgAnim/queues.html

Thursday, February 12, 2009

// Implementation of a Stack as a linked list
//purpose: To implement an array of list in a certain Stack


public class LLStack{
private java.util.LinkedList list=nw java.util.LinkedList();
public LLStack(){
}
public void clear(){
list.clear();
}
public boolean isEmpty(){
return list.isEmpty();
}
public Object topEl(){
if(isEmpty())
throw new java.util.EmptyStackException();
return list.getLast();
}
public Object pop(){
if(isEmpty())
throw new java.util.EmptyStackException();
return list.removeLast();
}
public void push(Object el){
list.addLast(el);
}
public String toString(){
return list.toString();
}
}

[Data structures and algorithms in Java 2nd Edition by: Adam Drozdek]

//This is the implementation of doubly linked list

public class IntDLLNode{
public int info;
public IntDLLNode next,prev;
public IntDLLNode(int el){
this(el,null,null);
}
public IntDLLNode(int el,IntDLLNode n,IntDLLNode p){
info=el;next=n;prev=p;
}
}

// This is the class of IntDLList

public class IntDLList{
private IntDLLNode head,tail;
public IntDLList(){
head=tail=null;
}
public boolean isEmpty(){
return head==null;
}
public void addToTail(int el){
if(!isEmpty()){
tail=new IntDLLNode(el,null,tail);
tail.prev.next=tail;
}
else head=tail=new IntDLLNode(el);
}
public int removeFromTail(){
int el=tail.info;
if(head==tail)//if only one node in the list;
head=tail=null;
else{ // if more than one node in the list;
tail=tail.prev;
tail.next=null;
}
return el;
}
}
[Data Structures and algorithms in Java 2nd Edition by: Adam Drozdek]

Sunday, February 8, 2009

it123

a.) Definition:
DOUBLE -ENDED LINKED LIST-it is a first and last reference. It can be the
arrangement of such qualities in every inputs that are available.



b.) illustration:

Double-ended linked list












c.)code/algorithm:


//Implementation of Double-Ended List
//Creating a new list of a link

public class Link {

private int idata;
private long ddata;
link next;

public Link(int nidata,long nddata){
iData=nidata;
dData=nddata;
}
}

//A class for a FirstLastLink

public class FirstLastLink{
private LinkFirst;
private LinkLast;

public FirstLastLink(){

first=null;
last=null;
}
public boolean isEmpty(){
return(first && last==null);
}
public void insertFirst(int nidata,long nddata){ //method in inserting in the first link
Link newLink=new Link(nidata,nddata);
newLink.next=first;
first=newLink;
}
public void insertLast(int nidata,long nddata){ //method in inserting in the last link
Link newLink=new Link(nidata,nddata);
newLink.next=last;
last=newLink;
}

public Link deleteFirst(int nidata,long nddata){
Link temp=first;
first=first.next;
return temp;
}

public Link deleteLast(int nidata,long nddata){
Link temp2=last;
last=last.next;
return temp2;
}

public void displayList(){

System.out.println(The List(first--last):");
Link current=first;
Link current2=last;
while(current && current2 !=null){
current.displayList();
current.current.next;
current.current2.next;
}
System out.println(" ");
}
}

// Application of the FirstLastApp

public class FirstLastApp{
public static void main(String[]args){

FirstLastList theList=new FirstLastList();

theList.insertFirst(1, 1,000);
theList.insertFirst(2, 2,000);
theList.insertFirst(3, 3,000);

theList.insertLast(4, 4,000);
theList.insertLast(5, 5,000);
theList.insertLast(6, 6,000);


System.out.println(theList);
theList.deleteFirst();
theList.deleteLast();

System.out.println(theList);
}
}
d.) Reference:
[jeany acoja-for the implementation of code]

Monday, February 2, 2009

IT123A0809

A.) DEFINITION-Stack (data structure)- a stack is an abstract data type and data structure based on the principle of Last In First Out (LIFO). For example, in the real world situation,a compilation of books. It emphasizes the order or sequence method of objects before it goes to another one.
And according to Adam Drozdek that "stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data".[from Java Structures and algorithms in java]


B.) Illustration:











C.)REFERENCES:
http://en.wikipedia.org/wiki/Stack_(data_structure)
http://en.wikipedia.org/wiki/File:Data_stack.svg