Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you just do A and B part. And please with solutions with codes Project Definition: In this project, you will implement common data structures
Can you just do A and B part. And please with solutions with codes
Project Definition: In this project, you will implement common data structures such as vector and stack to EREE. Please, read each part carefully, and pay attention to Assumptions and Constraints section. Part A. In this part, you will add vector to EREE. Introduce new operators newvector, updatevector, read-vector, length-vector, and swap-vector with the following definitions: (50 pts) newvector: ExpVal x ExpVal VecVal update-vector: VecVal x ExpVal x ExpVal Unspecified read-vector: VecVal x ExpVal ExpVal length-vector: VecVal ExpVal swap-vector: VecVal ExpVal ExpVal Unspecifled copy-vector: VecVal VecVal This leads us to define value types of EREF as: VecVal =(Ref(ExpVal)) ExpVal = Int + Bool + Proc + VecVal + Ref ( ExpVal ) DenVal = ExpVal Operators of vectors is defined as follows; newvector (length, value) initializes a vector of size length with the value value. update-vector(vec, index, value) updates the value of the vector vec at index index by value value. read-vector (vec, index) returns the element of the vector vec at index index. length-vector (vec) returns the length of the vector vec. swap-vector (vec, index, index) swaps the values of the indexes in the vector vec. copy-vector (vec) initializes an new vector with the same values of the given vector vec. (Creates a deep copy of the given vector.) Part B. In this part, you will implement a Stack using vectors that you implemented in Part A. Stack is a linear type of data structure that follows the LIFO (Last-In-First-Out) principle and allows insertion and deletion operations from one end of the stack data structure, that is top. In other words, whenever pop is called, the element that is added latest is removed and returned from the stack. You will implement the following operators of Stack with the given grammar: newstack (L) returns an empty stack with max-size L. push (s, val) adds the element val to the stack s. If the stack is full it throws a stack overflow error. pop (s) removes the last element of the stack s and returns its value. stack-size(s) returns the number of elements in the s. peek (s) returns the value of the last element in the stack s without removal, empty-stack? (s) returns true if there is no element inside the stack s and false otherwise. print-stack (s) prints the elements in the stack s Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started