My CSC 220 teacher has given this as a homework assignment and starting it has not made much sense and am generally lost on this assignment help would be much appreciated. I put everything from the assignment power point slides she gave us in here so the expert has everything im working with as well.
Dequeue
Please implement your own Dequeue class which has following methods
boolean add(E e)= void addLast(E e)
void addFirst(E e)
E getFirst( ) = E peek( )
E getLast( )
E removeFirst() E removeLast()
Case 1 Queue
Create a queue which is an instance of Dequeue. The queue should perform with given following input and print the correct output.
Input format
The first line contains an integer of q :
q specifies the number of queries which follows in the next lines
Each of the q next lines contains a single query in the form of one of following 3 types :
1 x: Enqueue element into the end of the queue.
2: Dequeue the element at the front of the queue.
3: Print the element at the front of the queue.
sample input
10
1 42
2
1 14
3
1 28
3
1 60
1 78
2
2
sample output
14
14
Case 2. Stack
Create a a stack which is an instance of Dequeue. The stack should perform with given following input and print the correct output.
Input format
Any string of postfix expression
Example “34+78+*”
Output
The value of evaluation
105
program prompt | input | correct output | notes |
---|---|---|---|
>For which case do you want to operate your deque | 1 | ||
>Please enter your input |
10 1 42 2 1 14 3 1 28 3 1 60 1 78 2 2 |
14 14 |
12 points |
>For which case do you want to operate your deque | 2 | ||
>Please enter your input | 34+78+* | 105 | 12 points |
>For which case do you want to operate your deque | 1 | ||
>Please enter your input |
6 1 45 2 1 8 2 1 88 3 |
88 | 12 points |
>For which case do you want to operate your deque | 2 | ||
>Please enter your input | 24+3/ | 2 | 12 points |
>For which case do you want to operate your deque | 2 | ||
>Please enter your input | 88/121-+* | 2 | 12 points |
EDIT:
I don't know what the equals signs mean between the functions but after trying to attempt to set up the shell to this program I think it is supposed to mean the functions are meant to do the same thing? I can't respond to the anon comment so this is how I'm going to do so. I know the assignment really doesn't seem to make sense.
Edit: Language is Java
Find below the source code
MyDequeueTest.java
import java.util.Scanner;
class MyDequeue<E>{
class Node{
E e;
Node next;
Node prev;
Node(E e){
this.e=e;
next=prev=null;
}
}
Node head,tail;
MyDequeue(){
head=null;
tail=null;
}
boolean add(E e) {
if(head==null) {
head=new
Node(e);
tail=head;
}
else {
Node temp=new
Node(e);
tail.next=temp;
temp.prev=tail;
tail=temp;
}
return true;
}
void addFirst(E e) {
if(head==null) {
head=new
Node(e);
tail=head;
}
else {
Node temp=new
Node(e);
head.prev=temp;
temp.next=head;
head=temp;
}
}
E getFirst() {
if(head==null)
return
null;
return head.e;
}
void addLast(E e) {
add(e);
}
E peek() {
return getFirst();
}
E getLast() {
if(tail==null)
return
null;
return tail.e;
}
E removeFirst() {
if(head==null)
return
null;
E temp=head.e;
if(head==tail)
head=tail=null;
else
head=head.next;
return temp;
}
E removeLast() {
if(tail==null)
return
null;
E temp=tail.e;
if(head==tail)
head=tail=null;
else
tail=tail.prev;
return temp;
}
}
public class MyDequeueTest{
public static void main(String[] args) {
Scanner sc=new
Scanner(System.in);
int mode;
System.out.print("For which case do
you want to operate your deque:");
mode=sc.nextInt();
if(mode==1) {
MyDequeue<Integer> q=new MyDequeue<Integer>();
int
noQuery;
System.out.print("Please enter you input");
noQuery=sc.nextInt();
while(noQuery-->0) {
int query=sc.nextInt();
if(query==1)
q.add(sc.nextInt());
if(query==2) {
q.removeFirst();
}
if(query==3)
System.out.println(q.getFirst());
}
}
if(mode==2) {
MyDequeue<Integer> q=new MyDequeue<Integer>();
String
input;
System.out.print("Please enter you input");
String
temp=sc.nextLine();
input=sc.nextLine().trim();
System.out.println(input);
for(int
i=0;i<input.length();i++) {
char c=input.charAt(i);
if(c=='+' || c=='-' || c=='*' || c=='/') {
int first,second;
second=q.removeLast();
first=q.removeLast();
if(c=='+')
q.add(first+second);
if(c=='-')
q.add(first-second);
if(c=='*')
q.add(first*second);
if(c=='/')
q.add(first/second);
}
else
q.add(c-'0');
//System.out.println((int)(c-'0'));
}
System.out.println(q.removeLast());
}
}
}
--------------------------------------------------
Sceenshot of runs
coding Practice/src/com/HomeworkLib/java8/MyDequeue Test.java - Eclipse IDE ce Refactor Navigate Search Project Run Window Help B&O ION 3. IN -L- - - - - U 1 2 !- 1 - - MyDequeue Te... 7 e rs Properties 474 Servers Data Source Explorer Snippets Console X E B 99 E <terminated> MyDequeue Test [Java Application] C:\Program FilesVava\jdk-13.0.1\bin\javaw.exe ( For which case do you want to operate your deque: 1 Please enter you input 1 45 198 109 111 112 113 GWN 116 if (c=='/')
Llice/SFILmm Leyy/JdVdo/ lviyDequeuerest.javd - Elipse IDE stor Navigate Search Project Run Window I IM 3.05FX Help -9-9- 3-6- queueTe... 7 e rs Properties 474 Servers Data Source Explorer Snippets Console X 8 | 2 b[E |=| | | | <terminated> MyDequeueTest [Java Application] C:\Program FilesVava\jdk-13.0.1\bin\javaw.exe (I For which case do you want to operate your deque:2 Please enter you input88/121-+* 88/121-+* if(c=='/') q.add(first/s
My CSC 220 teacher has given this as a homework assignment and starting it has not...
(java) Please implement your own Dequeue class which has following methods •boolean add(E e)= void addLast(E e) // two methods are the same. You could implement either one • •void addFirst(E e) • •E getFirst( ) = E peek( ) // two methods are the same. You could implement either one •E getLast( ) •E removeFirst() •E removeLast() Case 1 : Queue •Create a queue which is an instance of Dequeue. The queue should perform with given following input and print...
Python coding conceptual questions - Conceptual Questions Suppose you are given a (strange) computer that can only perform the following instructions (in addition to if and while): S-create_stack() create stack makes a new stack s iS.pop() removes the top item from stack s and places it in variable i .S.push (i) makes item i the top item in stack s Solve the following problems and justify your answers: 1. (10 pts) Show how you can use these operations to implement...
This is python programming. Please answer the questions based on python programming. 1.Answer “True/False” for the following statements (4 points each): a. The Stack follows the LILO principle. b. The Queue follows the FIFO principle c. The Deque follows the FILO principle. d. The Stack needs two references to achieve a worst case complexity of O(1). e. The Queue needs two references to achieve a worst case complexity of O(1). f. The Stacks always adds a node to the top....
HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD COMMENTS: stackARRAY: #include<iostream> #define SIZE 100 #define NO_ELEMENT -999999 using namespace std; class Stack { int arr[SIZE]; // array to store Stack elements int top; public: Stack() { top = -1; } void push(int); // push an element into Stack int pop(); // pop the top element from Stack int topElement(); // get the top element void display(); // display Stack elements from top to bottom }; void Stack...
In this assignment you will be implementing two Abstract Data Types (ADT) the Queue ADT and the Stack ADT. In addition, you will be using two different implementations for each ADT: Array Based Linked You will also be writing a driver to test your Queue and Stack implementations and you will be measuring the run times and memory use of each test case. You will also be adding some functionality to the TestTimes class that you created for Homework 1....
1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...
JAVA LANG PLEASE: I have follwed these below guidelines but when i run my queue test it is not executing but my stack is working fine, can you fix it please! MyQueue.java Implement a queue using the MyStack.java implementation as your data structure. In other words, your instance variable to hold the queue items will be a MyStack class. enqueue(String item): inserts item into the queue dequeue(): returns and deletes the first element in the queue isEmpty(): returns true or false...
how do I change my code to generic form *********************************************************************** public class UnboundedStackQueue { //question#3 } class Stack { Node head; int size; Stack() //default constructor { this.head=null; this.size=0; } //Input = data //Output = void (just adds value to list) // method pushes elements on stack // time: O(1) // space: O(1) public void push(int data) { Node node=new Node(data); node.next=head; head=node; size++; } //Input = none //Output = top of stack // method pops value from top of...
my question is on a java program. i have added all instructions for this homeowrk assignment. from how the input is entered and what the output should read. im seeing if i can get a psuedo code setup for how the algorithm should be setup. Build an Intersection Check program. User inputs two points as x-y coordinates in twodimension space. Two points represent two end points of a line segment. Then, user can input second two points for the second...
It is C++ problems, please explain your each line of code as well. Task 1: Implement/ Hard Code a Doubly Linked Lists and make it a Stack. Do not use ::list:: class from the STD library for this example. The user will input a string and the program will output the string backwards. Displaying correct Stack implementation. Utilize the conventional static methods as needed. push() pop() empty() peek() peek() Sample Execution Please input String: happy yppah Task 2: Implement /...