Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. public class ArrayList{
  2.     public Integer[] list;
  3.     int numElement;
  4.    
  5.     public ArrayList() {
  6.         list = new Integer[] {0,0,1,1,7,0,1,3};
  7.         numElement = 8;
  8.     }
  9.    
  10.     public void remove(Integer target) {
  11.         numElement = removeAt(target, 0, 0);
  12.     }
  13.    
  14.     public int removeAt(Integer target, int cur_index, int array_index) {
  15.         if (cur_index == numElement) {
  16.             return 0;
  17.         }
  18.         if (list[cur_index].compareTo(target) != 0 && list [array_index].compareTo(target) != 0) {
  19.             return (1 + removeAt(target, cur_index + 1, array_index + 1));
  20.         } else {
  21.             while (list[cur_index].compareTo(target) == 0) {
  22.                 cur_index++;
  23.             }
  24.             list[array_index] = list[cur_index];
  25.             return (1 + removeAt(target, cur_index + 1, array_index + 1));
  26.         }
  27.     }
  28.    
  29.     public static void main(String[] args){
  30.         ArrayList a = new ArrayList();
  31.         a.remove(1);
  32.         for(Integer i : a.list){
  33.             System.out.println(i);
  34.         }
  35.         System.out.println("num elements " + a.numElement);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement