Last active
August 29, 2015 13:57
-
-
Save Bjacksonshorts/9418398 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ListRunner{ | |
public static void main(String args[]){ | |
MyList ml = new MyList(); | |
//for( i = 0; i< 20; i++) | |
ml.add(1); | |
ml.add(2); | |
ml.add(3); | |
ml.add(4); | |
ml.add(5); | |
ml.add(6); | |
ml.add(7); | |
ml.add(8); | |
ml.add(9); | |
ml.add(10); | |
System.out.println(ml.get(1)); | |
System.out.println(ml.get(2)); | |
System.out.println(ml.get(3)); | |
System.out.println(ml.get(4)); | |
System.out.println(ml.get(5)); | |
System.out.println(ml.get(6)); | |
System.out.println(ml.get(7)); | |
System.out.println(ml.get(8)); | |
System.out.println(ml.get(9)); | |
System.out.println(ml.get(10)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyList{ | |
private int[] arr; | |
private int[] newArr; | |
private int lastUsedIndex; | |
public MyList(){ | |
arr = new int[1]; | |
lastUsedIndex = 0; | |
} | |
public void add(int e){ | |
if(arr.length <= lastUsedIndex){ | |
newArr = new int[lastUsedIndex + 1]; | |
newArr[lastUsedIndex] = e; | |
for(int i = 0 ;i < lastUsedIndex; i ++){ | |
arr = new int[newArr.length]; | |
} | |
arr = newArr; | |
//System.out.println(arr[1]); | |
// System.out.println(newArr(length); | |
}else{ | |
arr[lastUsedIndex] = e; | |
//System.out.println(arr[0]); | |
} | |
lastUsedIndex++; | |
//System.out.println(e); | |
} | |
public int get(int index){ | |
return arr[2]; | |
} | |
public void addAll(int[] e){ | |
/////////////////////////////////////////////////////////// | |
//add all of the elements in an array into the array list// | |
/////////////////////////////////////////////////////////// | |
} | |
public int size(){ | |
return lastUsedIndex; | |
//return the size of the arrayList// | |
//////////////////////////////////// | |
} | |
public int remove(){ | |
arr[lastUsedIndex] = arr[lastUsedIndex - 1]; | |
return arr[lastUsedIndex]; | |
} | |
public int arraycont(){ | |
return arr[0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment