Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a brief discussion (2-4 sentences) on each of these algorithms 1. Algorithm that sets last equal to the last element in a queue, leaving

write a brief discussion (2-4 sentences) on each of these algorithms
image text in transcribed
image text in transcribed
1. Algorithm that sets last equal to the last element in a queue, leaving the queue unchanged WHILE (NOT IsEmpty(myQueue)) Dequeue(myQueue, last) Enqueue(newQueue, last) WHILE (NOT IsEmtpy(newQueue)) Dequeue(newQueue, item) Enqueue(myQueue, item) 2. Algorithm to create a copy of myQueue, leaving myQueue unchanged. WHILE (NOT IsEmpty(myQueue)) Dequeue(myQueue, last) Enqueue(newQueue, last) WHILE (NOT IsEmtpy(newQueue)) Dequeue(newQueue, item) Enqueue(myQueue, item) Enqueue(copyQueue, item) Algorithm Replace that takes a stack and two items. If the first item is in the stack, replace it with the second item, leaving the rest of the stack unchanged. Replace(myStack, first, second) Pop(myStack, item) WHILE (Item NOT equal first) Push(newStack, item) Pop(myStack, item) IF (NOT IsEmpty(myStak)) Push(newStack, second) WHILE (NOT IsEmtpy(newStack)) Pop(newStack, item) Push(myStack, item) 3. Algorithm Replace that takes a queue and two items. If the first item is in the queue, replace it with the second item, leaving the rest of the queue unchanged Replace(myQueue, first, second) Dequeue(myQueue, item) WHILE (Item NOT equal first) Enqueue(newQueue, item) Dequeue(myQueue, item) IF (NOT IsEmpty(myQueue)) Enqueue(newQueue, second) WHILE (NOT IsEmtpy(newQueue)) Dequeue(newQueue, item) Enqueue(myQueue, item)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Distributed Relational Database Architecture Connectivity Guide

Authors: Teresa Hopper

4th Edition

0133983064, 978-0133983067

More Books

Students also viewed these Databases questions

Question

Identify the cause of a performance problem. page 363

Answered: 1 week ago