Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

python - How to define a function that expects a stack as an argument? (full question below)

Can anyone help me with this question? I'm fairly new to coding so help would be much appreciated

Qn: Define a function that expects a stack as an argument. The function builds and returns an instance of LinkedQueue that contains the elements in the stack. The function assumes that the stack has the interface described in the previous stack section. The function's postconditions are that the stack is left in the same state as it was before the function was called, and that the queue's front element is the one at the top of the stack.

question from:https://stackoverflow.com/questions/65895845/how-to-define-a-function-that-expects-a-stack-as-an-argument-full-question-bel

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

looks school work :D for a stack you can only push/pop on it. 1st, pop elements, 1 by 1, to create the linkedList, and push the popped elements to a reversed stack. 2nd, pop everything from the reversed stack and push back into original stack.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...