.
This commit is contained in:
		
							
								
								
									
										9
									
								
								bac1/q2/algo/tp8/AdditiveArrayList.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								bac1/q2/algo/tp8/AdditiveArrayList.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| import java.util.Arrays; | ||||
|  | ||||
| public class AdditiveArrayList<T> extends MyArrayList<T>{ | ||||
| 	public void makeSpaceIfNeeded(){ | ||||
| 		if(T1.length == size){ | ||||
| 			T[] temp = Arrays.newInstance(size-1); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										54
									
								
								bac1/q2/algo/tp8/ArrayListTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								bac1/q2/algo/tp8/ArrayListTest.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,54 @@ | ||||
| import java.util.ArrayList; | ||||
| import java.util.Random; | ||||
|  | ||||
| public class ArrayListTest { | ||||
|  | ||||
| 	public static ArrayList<String> create(int n){ | ||||
| 		ArrayList<String> ret = new ArrayList<String>(); | ||||
| 		for (;n > 0 ; n--) { | ||||
| 			String random_Word = ""; | ||||
| 			Random rand = new Random(); | ||||
| 			int str_size = rand.nextInt(1, 50); | ||||
| 			for(int i =0; i < str_size; i++){ | ||||
| 				random_Word += (char) rand.nextInt(32, 126); | ||||
| 			} | ||||
| 			ret.add(random_Word); | ||||
| 		} | ||||
| 		return ret; | ||||
| 	} | ||||
|  | ||||
| 	public static void add(ArrayList<String> l, String s){ | ||||
| 		l.add(s); | ||||
| 	} | ||||
|  | ||||
| 	public static void empty(ArrayList<String> l){ | ||||
| 		l.clear(); | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	public static void display(ArrayList<String> l){ | ||||
| 		System.out.print("["); | ||||
| 		for (String e : l) { | ||||
| 			System.out.print(e); | ||||
| 			System.out.print(", "); | ||||
| 		} | ||||
| 		System.out.println("]"); | ||||
| 	} | ||||
|  | ||||
| 	public static void main(String[] args) { | ||||
| 		ArrayList<String> a; | ||||
|  | ||||
| 		a = create(5); | ||||
| 		display(a); | ||||
|  | ||||
| 		add(a, "The lazy brown fox jump over the lazy fence"); | ||||
| 		display(a); | ||||
|  | ||||
| 		empty(a); | ||||
| 		display(a); | ||||
| 		 | ||||
| 		add(a, "The lazy brown fox jump over the lazy fence"); | ||||
| 		display(a); | ||||
|  | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										35
									
								
								bac1/q2/algo/tp8/MyArrayList.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								bac1/q2/algo/tp8/MyArrayList.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | ||||
| import java.util.Arrays; | ||||
|  | ||||
| public abstract class MyArrayList<T> { | ||||
| 	protected T T1[], temp[]; | ||||
| 	protected int size; | ||||
|  | ||||
| 	public int size(){ | ||||
| 		return size; | ||||
| 	} | ||||
| 	 | ||||
| 	public int physicalSize(){ | ||||
| 		return T1.length + temp.length + size * Integer.SIZE; | ||||
| 	} | ||||
|  | ||||
| 	public T get(int i){ | ||||
| 		return T1[i]; | ||||
| 	} | ||||
|  | ||||
| 	public void add(T o){ | ||||
| 		makeSpaceIfNeeded(); | ||||
| 		T1[size++] = o; | ||||
| 	} | ||||
|  | ||||
| 	public void add(int i, T o){ | ||||
| 		makeSpaceIfNeeded(); | ||||
| 		temp = Arrays.copyOfRange(T1, i, size-1); | ||||
| 		T1[i] = o; | ||||
| 		for(int j = 1; j <= temp.length; j++){ | ||||
| 			T1[j + i] = temp[i]; | ||||
| 		} | ||||
| 		size++; | ||||
| 	} | ||||
|  | ||||
| 	abstract void makeSpaceIfNeeded(); | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								bac1/q2/algo/tp8/TP8.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bac1/q2/algo/tp8/TP8.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user