Hi guys, I need some serious help in relation to Java Programming.
I need to do the following:
In this lab you will modify the SimpleListADT so that it provides an iterator() method for use by a client, alter the implementation so that it uses arrays, and change the sort method.
Since I suck at JAVA, I tried to do this in C Language. Can someone look over my C Code and Convert it to JAVA, please??
data = [two][one][four][][three][];
links = [4][0][-1][][2][];
freelist = [][][][5][][-1];
full(){ //checks whether data/links array are full
int full = 1;
for(int i = 0; i < freelist.length; i++){
if(freelist != NULL)
full = 0;
return full; //1 = full and 0 = not full
}
empty(){
int empty = 1;
for(int i = 0; i < data.length; i++){
if(data != NULL)
empty = 0;
return full; //1 = empty and 0 = not empty
}
equals() //not really sure what this function is supposed to do
iterator(){ //iterates through arrays and prints out data
int i = 1; //start of data array
print data; //print first array
while(links != -1){
i = links; //assign index to i
print data; //print data
} //should ouput: one two three four
}
insertItem(Comparable item){ //because no position specified, i will assume to add to first free space
if(full())
print "error, array is full";
else {
for(int i = 0; i < freekist.length; i++){ //find first free location
if(freelist != NULL)
break;
}
links = freelist; //put location in links
data[links] = item; //put item into data
temp = links;
links[data[temp]] = -1; //show where end of array is
}
}
insertItem(Comparable item, int position){
if(full())
print "error, array is full";
else {
if(data[position] == NULL){
links[position] = freelist[position]; //put location in links
data[links[position]] = item; //put item into data
temp = links[position];
links[data[temp]] = -1; //show where end of array is
else
print "error, location already in use";
}
}
removeItem(int position){
if (data[position] == NULL)
print "error,position already empty";
else {
data[position] = NULL; //remove data
for(int i = 0; i < links.length; i++){
if(links == position){
links == NULL; //remove link to data
break;
}
}
freelist[position] = i; //add to freelist
}
}
Or feel free to do the entire program and I will "repay" you back with my Web Designing experties such as HTML, CSS, Flash, etc.
ps. I attached my previous lab so you can refer to that if need be. It uses nodes.
Thank you so much!
I need to do the following:
In this lab you will modify the SimpleListADT so that it provides an iterator() method for use by a client, alter the implementation so that it uses arrays, and change the sort method.
Since I suck at JAVA, I tried to do this in C Language. Can someone look over my C Code and Convert it to JAVA, please??
data = [two][one][four][][three][];
links = [4][0][-1][][2][];
freelist = [][][][5][][-1];
full(){ //checks whether data/links array are full
int full = 1;
for(int i = 0; i < freelist.length; i++){
if(freelist != NULL)
full = 0;
return full; //1 = full and 0 = not full
}
empty(){
int empty = 1;
for(int i = 0; i < data.length; i++){
if(data != NULL)
empty = 0;
return full; //1 = empty and 0 = not empty
}
equals() //not really sure what this function is supposed to do
iterator(){ //iterates through arrays and prints out data
int i = 1; //start of data array
print data; //print first array
while(links != -1){
i = links; //assign index to i
print data; //print data
} //should ouput: one two three four
}
insertItem(Comparable item){ //because no position specified, i will assume to add to first free space
if(full())
print "error, array is full";
else {
for(int i = 0; i < freekist.length; i++){ //find first free location
if(freelist != NULL)
break;
}
links = freelist; //put location in links
data[links] = item; //put item into data
temp = links;
links[data[temp]] = -1; //show where end of array is
}
}
insertItem(Comparable item, int position){
if(full())
print "error, array is full";
else {
if(data[position] == NULL){
links[position] = freelist[position]; //put location in links
data[links[position]] = item; //put item into data
temp = links[position];
links[data[temp]] = -1; //show where end of array is
else
print "error, location already in use";
}
}
removeItem(int position){
if (data[position] == NULL)
print "error,position already empty";
else {
data[position] = NULL; //remove data
for(int i = 0; i < links.length; i++){
if(links == position){
links == NULL; //remove link to data
break;
}
}
freelist[position] = i; //add to freelist
}
}
Or feel free to do the entire program and I will "repay" you back with my Web Designing experties such as HTML, CSS, Flash, etc.
ps. I attached my previous lab so you can refer to that if need be. It uses nodes.
Thank you so much!