salmantariq
Technical User
hi this is my assignment i ve done part of it it s compiling but i dont get the results tth i want. my 1st array gets filled and everything but when i want to put something greater than the size of 1st array it should go to 2nd arrays tht i made but it doesnt go there. link for assignment info is
I also need some help in Iterator class. i ve posted my LinkedArray class and ListIterator class below can u please help me with tht thanks alot!
import java.util. *;
import java.util.ListIterator.*;
public class LinkedArrayList
{
public ListNode head,tail, Link;
private int size, n;
private Object data;
private int current;
Object Arraylist[], Arraylistone[], Arraylistwo[];
Object first;
public LinkedArrayList(int increment)
{
n = increment;
head = null;
tail = null;
size = 0;
current = 0;
Arraylist = new Object[n+1];
}
public boolean isEmpty()
{
return (size == 0);
}
public int size()
{
return size;
}
public void add(int index, Object o)
{
if(index < n)
{
Arraylistone = Arraylist;
first = Arraylistone;
Arraylistone[index] = o;
size++;
}
else if(index > n)
{
Arraylistwo = Arraylist;
Arraylistone[n] = Arraylistwo;
Arraylistone[index] = Arraylistwo[index-(n-1)];
Arraylistone[index] = o;
size++;
}
}
public Object get(int index)
{
/* if(index < n)
{*/
return (Arraylistone[index]);
/*}
else if(index >= n)
{
return(Arraylistwo[index]);
}
return Arraylistwo[index];*/
}
public Object set(int index, Object o)
{
if(index < n)
{
Arraylistone[index] = o;
}
else if(index > n)
{
Arraylistwo[index] = o;
}
return Arraylistone[index];
}
public Object remove(int index)
{
Object c = Arraylistone[index];
Arraylistone[index] = null;
for(int i=index; i<n; ++i)
{
Arraylistone = Arraylistone[i+1];
}
--size;
return c;
}
}
-----------------------------------------------------------
import java.util. *;
import java.util.ListIterator.*;
public class LinkedArrayListIterator
{
public ListNode head,tail, Link;
private int size, n, index;
private Object data;
private int current;
private Object[] a;
Object Arraylist[], Arraylistone[], Arraylistwo[];
public LinkedArrayListIterator(LinkedArrayList l, Object[] a)
{
a = new Object[n+1];
l = new LinkedArrayList(n+1);
head = null;
tail = null;
size = 0;
current = 0;
}
public boolean hasNext()
{
for(int i = 0; i < Arraylist.length; i++)
{
if(Arraylist != null)
return true;
}
return false;
}
public Object next()
{
Object answer;
if(!hasNext())
throw new NoSuchElementException();
answer = Arraylist[index];
index++;
return answer;
}
}
I also need some help in Iterator class. i ve posted my LinkedArray class and ListIterator class below can u please help me with tht thanks alot!
import java.util. *;
import java.util.ListIterator.*;
public class LinkedArrayList
{
public ListNode head,tail, Link;
private int size, n;
private Object data;
private int current;
Object Arraylist[], Arraylistone[], Arraylistwo[];
Object first;
public LinkedArrayList(int increment)
{
n = increment;
head = null;
tail = null;
size = 0;
current = 0;
Arraylist = new Object[n+1];
}
public boolean isEmpty()
{
return (size == 0);
}
public int size()
{
return size;
}
public void add(int index, Object o)
{
if(index < n)
{
Arraylistone = Arraylist;
first = Arraylistone;
Arraylistone[index] = o;
size++;
}
else if(index > n)
{
Arraylistwo = Arraylist;
Arraylistone[n] = Arraylistwo;
Arraylistone[index] = Arraylistwo[index-(n-1)];
Arraylistone[index] = o;
size++;
}
}
public Object get(int index)
{
/* if(index < n)
{*/
return (Arraylistone[index]);
/*}
else if(index >= n)
{
return(Arraylistwo[index]);
}
return Arraylistwo[index];*/
}
public Object set(int index, Object o)
{
if(index < n)
{
Arraylistone[index] = o;
}
else if(index > n)
{
Arraylistwo[index] = o;
}
return Arraylistone[index];
}
public Object remove(int index)
{
Object c = Arraylistone[index];
Arraylistone[index] = null;
for(int i=index; i<n; ++i)
{
Arraylistone = Arraylistone[i+1];
}
--size;
return c;
}
}
-----------------------------------------------------------
import java.util. *;
import java.util.ListIterator.*;
public class LinkedArrayListIterator
{
public ListNode head,tail, Link;
private int size, n, index;
private Object data;
private int current;
private Object[] a;
Object Arraylist[], Arraylistone[], Arraylistwo[];
public LinkedArrayListIterator(LinkedArrayList l, Object[] a)
{
a = new Object[n+1];
l = new LinkedArrayList(n+1);
head = null;
tail = null;
size = 0;
current = 0;
}
public boolean hasNext()
{
for(int i = 0; i < Arraylist.length; i++)
{
if(Arraylist != null)
return true;
}
return false;
}
public Object next()
{
Object answer;
if(!hasNext())
throw new NoSuchElementException();
answer = Arraylist[index];
index++;
return answer;
}
}