Uploaded by fumoffuwins

Spring 23 Assignment 2 - LinkedList Stack

advertisement
COP 3530: Data Structures
Assignment – 2: LinkedList and Stack
Due Date & Time: Wednesday Feb 8, 2022, 11:59 pm
Instructor: Ahmad Waqas, PhD
Instructions:
➢ Submit the java project folders as a .zip file.
Task – 1:
Give the implementation of doubly linked list in Java. A doubly linked list contains data, address
of the next (successor) node and address of the previous (parent) node. Your program must have
the following methods:
• public void add (T data)
• public void add (int index, T data)
• public void addFirst (T data)
• public void addLast (T data)
• public T remove ( )
• public T remove (int index)
• public T removeFirst ( )
• public T removeLast ( )
• public String toString ( )
Task – 2:
Write a java program using Stack to convert the infix notation to postfix. Your program will ask
user to input the infix notation and will print out the equivalent postfix notation.
Following are the algorithmic steps to convert infix to postfix:
1) When an operand is read, it is immediately placed onto the output.
2) Operators and ( are not immediately output, so they must be saved on to the stack.
3) If we see a ), then we pop the stack, writing symbols until we encounter a
(corresponding) (, which is popped but not output.
4) If we see any other symbol +, *, (, then we pop entries from the stack until we find an
entry of lower priority. One exception is that we never remove a ( from the stack
except when processing a ). For the purposes of this operation, + has lowest priority
and ( highest.
5) When the popping is done, we push the operator onto the stack.
6) Finally, if we read the end of input, we pop the stack until it is empty, writing symbols
onto the output.
Note: You must use your own implementation of Stack. Do not use the Java libraries
(java.util.Stack)
COP3530 – Assignment 2
Page 1 of 1
Download