// Arup Guha
// 10/21/2026
// ArrayList adding removing from random locations.

import java.util.*;

public class TestArrayList {

	public static void main(String[] args) {
	
		// Create a test list and a random number generator.
		Random r = new Random();
		ArrayList<Integer> list = new ArrayList<Integer>();
		
		// Do 25 random operations.
		for (int i=0; i<25; i++) {
		
			// Build the list up for the first 5 ops.
			if (i<5) {
				
				// Add random item.
				int tmp = r.nextInt(100);
				list.add(tmp);
				System.out.println("Adding "+tmp+" to back of list.");
			}
			
			// Rest of the ops.
			else {
			
				// 60% adds
				int op = r.nextInt(10);
				if (op < 6) {
					
					// This time I add at a random index.
					int idx = r.nextInt(list.size());
					int add = r.nextInt(100);
					list.add(idx, add);
					System.out.println("Adding "+add+" to index "+idx);
				}
				
				// Here I remove from a random index.
				else {
					int idx = r.nextInt(list.size());
					int item = list.remove(idx);
					System.out.println("removed "+item+" from index "+idx);
				}
			}
		
			// So we can see what's happening.
			print(list);
		}
	}
	
	// Prints list.
	public static void print(ArrayList<Integer> list) {
		for (int i=0; i<list.size()-1; i++)
			System.out.print(list.get(i)+", ");
		System.out.println(list.get(list.size()-1));
	}

}
