uncharted314 commited on
Commit
7eb1eeb
·
verified ·
1 Parent(s): c951894

Update structure.json

Browse files
Files changed (1) hide show
  1. structure.json +29 -23
structure.json CHANGED
@@ -1,45 +1,51 @@
1
 
2
  [
3
  {
4
- "class_name": "ArrayStack",
5
- "function": "ArrayStack",
6
- "documentation": "",
7
- "block_code": "public ArrayStack() {\n backingArray = (T[]) new Object[INITIAL_CAPACITY];\n size = 0;\n }"
8
  },
9
  {
10
- "class_name": "ArrayStack",
11
- "function": "push",
12
- "documentation": "",
13
- "block_code": "public void push(T data) {\n if (data == null) {\n throw new IllegalArgumentException();\n }\n if (size == 0) {\n backingArray[0] = data;\n size++;\n return;\n }\n if (size == INITIAL_CAPACITY) {\n expand();\n }\n backingArray[size] = data;\n size++;\n }"
14
  },
15
  {
16
- "class_name": "ArrayStack",
17
- "function": "pop",
18
- "documentation": "",
19
- "block_code": "public T pop() {\n if (size == 0) {\n throw new NoSuchElementException();\n }\n T thisData = backingArray[size - 1];\n backingArray[size - 1] = null;\n size--;\n return thisData;\n }"
20
  },
21
  {
22
- "class_name": "ArrayStack",
23
  "function": "peek",
24
- "documentation": "",
25
- "block_code": "public T peek() {\n if (size == 0) {\n throw new NoSuchElementException();\n }\n return backingArray[size - 1];\n }"
26
  },
27
  {
28
- "class_name": "ArrayStack",
29
  "function": "getBackingArray",
30
- "documentation": "",
31
  "block_code": "public T[] getBackingArray() {\n // DO NOT MODIFY THIS METHOD!\n return backingArray;\n }"
32
  },
33
  {
34
- "class_name": "ArrayStack",
35
  "function": "expand",
36
- "documentation": "",
37
- "block_code": "private void expand() {\n T[] largerBackingArray = (T[]) new Object[backingArray.length * 2];\n int currInd = 0;\n while (currInd < backingArray.length) {\n largerBackingArray[currInd] = backingArray[currInd];\n currInd++;\n }\n backingArray = largerBackingArray;\n }"
38
  },
39
  {
40
- "class_name": "ArrayStack",
41
  "function": "size",
42
- "documentation": "",
43
  "block_code": "public int size() {\n // DO NOT MODIFY THIS METHOD!\n return size;\n }"
 
 
 
 
 
 
44
  }
45
- ]
 
1
 
2
  [
3
  {
4
+ "class_name": "ArrayQueue",
5
+ "function": "ArrayQueue",
6
+ "documentation": "/*\n * The initial capacity of the ArrayQueue.\n *\n * DO NOT MODIFY THIS VARIABLE.\n */\n /*\n * Do not add new instance variables or modify existing ones.\n */\n /**\n * Constructs a new ArrayQueue.\n */",
7
+ "block_code": "public ArrayQueue() {\n backingArray = (T[]) new Object[INITIAL_CAPACITY];\n front = 0;\n size = 0;\n }"
8
  },
9
  {
10
+ "class_name": "ArrayQueue",
11
+ "function": "enqueue",
12
+ "documentation": "/**\n * Adds the data to the back of the queue.\n *\n * If sufficient space is not available in the backing array, resize it to\n * double the current length. When resizing, copy elements to the\n * beginning of the new array and reset front to 0.\n *\n * Must be amortized O(1).\n *\n * @param data the data to add to the back of the queue\n * @throws java.lang.IllegalArgumentException if data is null\n */",
13
+ "block_code": "public void enqueue(T data) {\n if (data == null) {\n throw new IllegalArgumentException();\n }\n if (size == INITIAL_CAPACITY) {\n expand();\n backingArray[front + size] = data;\n size++;\n return;\n }\n if (size < INITIAL_CAPACITY && backingArray[INITIAL_CAPACITY - 1] != null) {\n int backingIndx = -(INITIAL_CAPACITY - (front + size));\n backingArray[backingIndx] = data;\n size++;\n return;\n } else {\n backingArray[front + size] = data;\n size++;\n return;\n }\n }"
14
  },
15
  {
16
+ "class_name": "ArrayQueue",
17
+ "function": "dequeue",
18
+ "documentation": "/**\n * Removes and returns the data from the front of the queue.\n *\n * Do not shrink the backing array.\n *\n * Replace any spots that you dequeue from with null.\n *\n * If the queue becomes empty as a result of this call, do not reset\n * front to 0.\n *\n * Must be O(1).\n *\n * @return the data formerly located at the front of the queue\n * @throws java.util.NoSuchElementException if the queue is empty\n */",
19
+ "block_code": "public T dequeue() {\n if (size == 0) {\n throw new NoSuchElementException();\n }\n T thisData = backingArray[front];\n backingArray[front] = null;\n if (front == backingArray.length - 1) {\n System.out.println(backingArray.length);\n System.out.println(front);\n front = front % (backingArray.length - 1);\n } else {\n front++;\n }\n size--;\n return thisData;\n }"
20
  },
21
  {
22
+ "class_name": "ArrayQueue",
23
  "function": "peek",
24
+ "documentation": "/**\n * Returns the data from the front of the queue without removing it.\n *\n * Must be O(1).\n *\n * @return the data located at the front of the queue\n * @throws java.util.NoSuchElementException if the queue is empty\n */",
25
+ "block_code": "public T peek() {\n if (size == 0) {\n throw new NoSuchElementException();\n }\n return backingArray[front];\n }"
26
  },
27
  {
28
+ "class_name": "ArrayQueue",
29
  "function": "getBackingArray",
30
+ "documentation": "/**\n * Returns the backing array of the queue.\n *\n * For grading purposes only. You shouldn't need to use this method since\n * you have direct access to the variable.\n *\n * @return the backing array of the queue\n */",
31
  "block_code": "public T[] getBackingArray() {\n // DO NOT MODIFY THIS METHOD!\n return backingArray;\n }"
32
  },
33
  {
34
+ "class_name": "ArrayQueue",
35
  "function": "expand",
36
+ "documentation": "/**\n * Helper method which expands the backing array\n *\n * Array will be expanded by adding INITIAL_CAPACITY to its current length.\n *\n */",
37
+ "block_code": "private void expand() {\n T[] largerBackingArray = (T[]) new Object[backingArray.length * 2];\n int counter = 0;\n int newArrIndx = 0;\n int currInd = front;\n while (counter < backingArray.length) {\n if (currInd == backingArray.length) {\n currInd = 0;\n }\n largerBackingArray[newArrIndx] = backingArray[currInd];\n counter++;\n newArrIndx++;\n currInd++;\n }\n backingArray = largerBackingArray;\n front = 0;\n }"
38
  },
39
  {
40
+ "class_name": "ArrayQueue",
41
  "function": "size",
42
+ "documentation": "/**\n * Returns the size of the queue.\n *\n * For grading purposes only. You shouldn't need to use this method since\n * you have direct access to the variable.\n *\n * @return the size of the queue\n */",
43
  "block_code": "public int size() {\n // DO NOT MODIFY THIS METHOD!\n return size;\n }"
44
+ },
45
+ {
46
+ "class_name": "ArrayQueue",
47
+ "function": "getFront",
48
+ "documentation": "",
49
+ "block_code": "public int getFront() {\n // DO NOT MODIFY THIS METHOD!\n return front;\n }"
50
  }
51
+ ]