Skip to content
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.

7 changes: 6 additions & 1 deletion src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ public static void main(String[] args) {

Deque<String> d1 = new ResizingArrayDeque<>();
// some test code here
d1.addFirst("pink");
d1.addFirst("brown");
System.out.println(d1.size());

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

d2.addFirst("pink");
d2.addFirst("brown");
System.out.println(d2.size());
}
}
10 changes: 8 additions & 2 deletions src/ResizingArrayDeque.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ public int size() {
public void addFirst(ItemType item) {
// consider the case of adding to an empty list
// consider the case of adding to a non-empty list
if (item == null) {
throw new NullPointerException();
}

// 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 @@ -47,7 +51,9 @@ public void addFirst(ItemType item) {
public void addLast(ItemType item) {
// consider the case of adding to an empty list
// consider the case of adding to a non-empty list

if (item == null) {
throw new NullPointerException();
}
// 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 Down Expand Up @@ -109,7 +115,7 @@ private void checkSize() {
temp[i] = data[i];
}

// Step 3 - repoint/refererence data to point to new array
// Step 3 - repoint/reference data to point to new array
data = temp;

// Optional:
Expand Down
7 changes: 7 additions & 0 deletions src/SinglyLinkedDeque.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public int size() {
return size;
}


/**
* Adds an item to the front of the deque.
*
Expand All @@ -36,6 +37,10 @@ public int size() {
public void addFirst(ItemType item) {
// consider the case of adding to an empty list
// consider the case of adding to a non-empty list
if (item == null) {
throw new NullPointerException();
}

}

/**
Expand All @@ -47,6 +52,7 @@ public void addFirst(ItemType item) {
public void addLast(ItemType item) {
// consider the case of adding to an empty list
// consider the case of adding to a non-empty list

}

/**
Expand All @@ -63,6 +69,7 @@ public ItemType removeFirst() {

// if not empty:
// 0. figure out a way to access the item in the front

// 1. make a variable to save a copy of the item at the front
// 2. remove the item at the front
// 3. return the variable that has the saved copy of the item at the front
Expand Down