English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

collections frame work should not be used

2006-06-19 07:46:19 · 3 answers · asked by j_davis_1980 1 in Computers & Internet Programming & Design

3 answers

STACK
----------
public class pArrayStackInt{
protected int head[];
protected int pointer;

public pArrayStackInt(int capacity){
head = new int[capacity];
pointer = -1;
}
public boolean isEmpty(){
return pointer == -1;
}
public void push(int i){
if(pointer+1 < head.length)
head[++pointer] = i;
}
public int pop(){
if(isEmpty())
return 0;
return head[pointer--];
}
}

QUEUE:-
------------
public class pArrayQueue{
protected Object[] array;
protected int start,end;
protected boolean full;

public pArrayQueue(int maxsize){
array = new Object[maxsize];
start = end = 0;
full = false;
}

public boolean isEmpty(){
return ((start == end) && !full);
}

public void insert(Object o){
if(!full)
array[start = (++start % array.length)] = o;
if(start == end)
full = true;
}

public Object remove(){
if(full)
full = false;
else if(isEmpty())
return null;
return array[end = (++end % array.length)];
}
}
courtesy:-
http://www.javacommerce.com/displaypage.jsp?name=javadata2.sql&id=18214#Array_Queue

Check up the site for other examples.

2006-06-25 00:45:10 · answer #1 · answered by mashiur1973 2 · 1 1

i have one or two powerpoint pres from it in my computer , but now l am not at home , if argent need them contact me with mail or IM to attach it for u, i gathered them for lesson Data Structure in 3 years later

2006-06-20 05:15:22 · answer #2 · answered by Spitrabergâ?¢ 4 · 0 0

You can also check in this site. Lots of examples...

http://www.javaalmanac.com/

2006-07-02 00:49:53 · answer #3 · answered by Custom fan 2 · 0 0

fedest.com, questions and answers