Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test finish #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ public static void main(String[] args) {
Deque<String> d1 = new ResizingArrayDeque<>();
// some test code here

// Max: both remove methods on if array is empty, print out nothing to remove
d1.removeFirst();
System.out.println(d1);
d1.removeLast();
System.out.println(d1);

//Max: received an error
//Max: attempted to fix, received a null instead of error
//Max: third attempt to fix, received same error

d1.addFirst("Hello");
System.out.println(d1);

Deque<String> d2 = new SinglyLinkedDeque<>();
// some test code here

Expand Down
62 changes: 62 additions & 0 deletions src/ResizingArrayDeque.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.w3c.dom.Node;

public class ResizingArrayDeque<ItemType> implements Deque<ItemType> {
// constants
public static int DEFAULT_CAPACITY = 10;
Expand Down Expand Up @@ -34,6 +36,31 @@ public void addFirst(ItemType item) {
// consider the case of adding to an empty list
// consider the case of adding to a non-empty list

ItemType[] temp = data;
//Max: Step 1 - Check if it is empty

if (size == 0){
// Max: if it is empty, add item to the arraylist

// Max: Increase the size of array
size++;
} else{ // Max: If it is not empty
// Max: Create a temporary variable to store the current first item in array list

//Max: go through the arraylist and store the latest item in the temporary
for (int i = 0; i < data.length; i++) {
temp = data;
}

//Max: store the temp so that it will still be in the list and increase the size

//Max: Add the item to the latest size which is currently null

//Max: successfully increase size, keeping recent addition and adding the newest one


}

// There is a private helper method checkSize() defined below to check/resize
// that you can call as needed to check if the array is full and resize it.
}
Expand All @@ -48,6 +75,17 @@ public void addLast(ItemType item) {
// consider the case of adding to an empty list
// consider the case of adding to a non-empty list

// Max: if the list is empty, just add to the first spot
if (size == 0){
// Max: add the item to the array and increase the size

} else { //Max: if it is not empty...
// Max: backtrack the array adding an index to each spot

//Max: replace index 0 with the item

}

// There is a private helper method checkSize() defined below to check/resize
// that you can call as needed to check if the array is full and resize it.
}
Expand All @@ -62,6 +100,13 @@ public ItemType removeFirst() {
// check if empty
// if empty: do nothing and return null

// Max: if the list is empty, send a message saying there is nothing to remove
if (size == 0){
System.out.println("This list is empty, nothing to remove");
return null;
} else { // Max: if the list does have something...
//Max: go through the array find the most recent index and remove it
}
// if there's only one item: is this a special case?

// if not empty:
Expand All @@ -83,6 +128,14 @@ public ItemType removeLast() {
// check if empty
// if empty: do nothing and return null

// Max: if the list is empty, send a message saying there is nothing to remove
if (size == 0){
System.out.println("This list is empty, nothing to remove");
return null;
} else { // Max: if the list does have something...

}

// if there is only one item: is this a special case?

// if not empty, has more than one item:
Expand Down Expand Up @@ -116,4 +169,13 @@ private void checkSize() {
temp = null;
} // end of if (need to resize)
}

// Max: adding the toString method to test the code
public String toString(){
String result = "";
for (int i = 0; i < size; i++) {
result += data[i] + " ";
}
return result;
}
}