Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UnorderedArrayList<T> extends ArrayListClass<T> {
- public UnorderedArrayList(){
- super();
- }
- public UnorderedArrayList(int size){
- super(size);
- }
- public void insertAt(int loc, T insertItem){
- if(loc < 0 || loc >= maxSize){
- System.err.println("Entered index out of range.");
- }
- else if(length >= maxSize){
- System.err.println("List is full!");
- }
- else{
- for(int i = length; i > loc; i--){
- list[i] = list[i - 1];
- }
- list[loc] = insertItem;
- length++;
- }
- }
- public int seqSearch(T searchItem){
- int loc;
- boolean found = false;
- for(loc = 0; loc < length; loc++){
- if(list[loc].equals(searchItem)){
- found = true;
- break;
- }
- }
- if(found){
- return loc;
- }
- else{
- return -1;
- }
- }
- public void remove(T removeItem){
- int loc;
- if(length == 0){
- System.err.println("List is empty!");
- }
- else{
- loc = seqSearch(removeItem);
- if(loc != -1){
- removeAt(loc);
- }
- else{
- System.out.println("The item to be deleted is not in the list!");
- }
- }
- }
- public void replaceAt(int loc, T replaceItem){
- if(loc < 0 || loc >= length){
- System.err.println("Entered index is out of range");
- }
- else{
- list[loc] = replaceItem;
- }
- }
- public void insertEnd(T insertItem){
- if(length >= maxSize){
- System.err.println("The list is full!");
- }
- else{
- list[length] = insertItem;
- length++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement