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
4 changes: 2 additions & 2 deletions src/main/java/com/example/project/ArrayList.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.project;
package main.java.com.example.project;

public class ArrayList<T> implements List<T> {
private int maxsize;
Expand Down Expand Up @@ -54,4 +54,4 @@ public void remove() {
else if (current == size)
current = 0;
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/example/project/ArrayQueue.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.project;
package main.java.com.example.project;

public class ArrayQueue<T> implements Queue<T> {
private int maxsize;
Expand Down Expand Up @@ -31,4 +31,4 @@ public T serve () {
size--;
return e;
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/example/project/ArrayStack.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.project;
package main.java.com.example.project;

public class ArrayStack<T> implements Stack<T> {
private int maxsize;
Expand All @@ -23,4 +23,4 @@ public void push(T e){
public T pop(){
return nodes[top--];
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/example/project/DLL.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.project;
package main.java.com.example.project;

public class DLL<T> {
private DLLNode<T> head;
Expand Down Expand Up @@ -76,4 +76,4 @@ public void removeBetween(T e1, T e2) {
// Example 3.1. Given the list: A ↔ B ↔ C ↔ D ↔ E ↔ F, removeBetween(’B’,
// ’E’) results in: A ↔ B ↔ E ↔ F.
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/example/project/DLLNode.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.project;
package main.java.com.example.project;

public class DLLNode<T> {
public T data;
Expand All @@ -19,4 +19,4 @@ public DLLNode(T data, DLLNode<T> next, DLLNode<T> previous) {
this.next = next;
this.previous = previous;
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/example/project/LinkedList.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.project;
package main.java.com.example.project;

public class LinkedList<T> implements List<T>{
private Node<T> head;
Expand Down Expand Up @@ -63,4 +63,4 @@ public T mostFrequentElement() {
// Example 1.1. Given the list l : A, B, C, B, C, D, E, mostFrequentElement() returns
// B.
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/example/project/LinkedPQ.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.project;
package main.java.com.example.project;

public class LinkedPQ<T> {
private int size;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/example/project/LinkedQueue.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.project;
package main.java.com.example.project;

public class LinkedQueue<T> implements Queue<T>{
private Node<T> head, tail;
Expand Down Expand Up @@ -34,4 +34,4 @@ public T serve() {
tail = null;
return x;
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/example/project/LinkedStack.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.project;
package main.java.com.example.project;

public class LinkedStack<T> implements Stack<T> {
private Node<T> top;
Expand All @@ -23,4 +23,4 @@ public T pop() {
top = top.next;
return e;
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/example/project/List.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.project;
package main.java.com.example.project;

public interface List<T> {
public void findFirst( );
Expand All @@ -10,4 +10,4 @@ public interface List<T> {
public boolean full( );
public boolean empty( );
public boolean last( );
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/example/project/Node.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.project;
package main.java.com.example.project;

public class Node<T> {
public T data;
Expand All @@ -15,4 +15,4 @@ public Node(T data, Node<T> next) {
this.data = data;
this.next = next;
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/example/project/PQElement.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.project;
package main.java.com.example.project;

public class PQElement<T> {
public T data;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/project/PQNode.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.project;
package main.java.com.example.project;

public class PQNode<T> {
public T data;
Expand Down
74 changes: 53 additions & 21 deletions src/main/java/com/example/project/QueueStackTester.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,63 @@
package com.example.project;
package main.java.com.example.project;

public class QueueStackTester {
public static <T> void split(Queue<T> q, Queue<T> oq, Queue<T> eq)
{
throw new UnsupportedOperationException("Not supported yet.");
// Write the recursive static method split that splits a queue of n elements into two
// queues. The elements with odd orders (i.e. 1st, 3rd, 5th ...) should be put in the
// first queue and elements with even orders (i.e. 2nd, 4th, 6th ...) should be put in
// the second queue. The original queue should remain unchanged at the end of the
// method.
// Example. Given the queue (A, B, C, D, E), split results in oq (A, C, E), and eq(B, D).
{
int indexCount = oq.length() + eq.length() ;

if (indexCount == q.length())
return;

T e = q.serve();
if (indexCount%2 == 0) {
if(!oq.full())
oq.enqueue(e);
}
else {
if(!eq.full())
eq.enqueue(e);
}
q.enqueue(e);

split(q, oq, eq);


}
public static <T> void remove(LinkedPQ<T> pq, int p)
{
throw new UnsupportedOperationException("Not supported yet.");
// Write a static method remove that removes every element in the priority queue
// having priority less than p.
// Example. Given pq: [A, 10], [D, 8], [B, 5], [E, 3], [C, 2] remove(pq, 5) results in
// pq: [A, 10], [D, 8], [B, 5].
if (pq.length() == 0)
return;

PQElement<T> e = null;
LinkedPQ<T> temp = new LinkedPQ<T>();

for(int i = pq.length(); i>0; i--) {
e = pq.serve();
if(e.p >= p) {
temp.enqueue(e.data, e.p);
}
}

if(temp.length() == 0)
return;

for(int i = temp.length(); i>0; i--) {
e = temp.serve();
pq.enqueue(e.data, e.p);
}
}
public static <T> boolean search(Stack<T> st, T e)
{
throw new UnsupportedOperationException("Not supported yet.");
// Write the recursive static method search that searches for an element e in a stack st
// and returns true if it’s found or false otherwise. st should not change at the end of
// the method. You are not allowed to use any auxiliary data structures.
// Example. Given the stack st (top-to-bottom): 5, 7, 5, 3, 2. search(st, 3) returns
// true while search(st, 1) returns false.
if (st.empty())
return false;
boolean check = false;
T temp = st.pop();
if (temp.equals(e))
check = true;
check = check || search(st, e);
st.push(temp);
return check;


}
}
}
3 changes: 2 additions & 1 deletion src/test/java/com/example/project/TestQueueStack.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.example.project;
package test.java.com.example.project;
import main.java.com.example.project.*;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand Down