Question: There is no reason to actually build a stack in Rust. You would just use a Vec. For this quiz, however you are going to

There is no reason to actually build a stack in Rust. You would just use a Vec. For this quiz, however you are going to implement a stack using a linked list. We have a linked list implementation of a stack in Rust. The stack is defined as struct Stack head: Stackelem, where each link is simply an optional node defined as struct Valnode elem: i32, next: Stackelem, The elements of the stack (each element in the linked list) are therefore defined as You have a Stack that is initialized with let my_stack- Stack (head: None) You are to implement a push method and a pop method that can be invoked using my stack.push(7) The result of push is that an element is added to the top of the stack and for pop it is removed. Push does not return a value; pop returns the integer that is popped. The top of the stack is to be the first element in the linked list You may NOT use map Hints: Use self Neither function should be more than a couple of lines long. Look at the take method of Option 1-1 pub fn take(Anut self) OptionT> xcl lakes the value out of the aption, kuning a Mane in its place Examples let y-a. take) essert.en(y,Sone(2) lety .take assert.e (x, None) assert.egi (y, Nonc)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!