Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

Assignment 2 – Stacks |Johns Hopkins University CS 605.202 -ALL ANSWERS ARE CORRECT

Beoordeling
-
Verkocht
-
Pagina's
8
Cijfer
A+
Geüpload op
29-01-2023
Geschreven in
2022/2023

Assignment 2 – Stacks Write pseudo-code not Java for problems requiring code. You are responsible for the appropriate level of detail. 1. a) Use the operations push, pop, peek and empty to construct an operation which sets i to the second element from the top of the stack, leaving the stack unchanged. h = pop (s); i = pop (s); push (s, i); push (s, h); b) Use the operations push, pop, peek and empty to construct an operation which sets i to the nth element from the top of the stack, leaving the stack without its top n elements. You are given integer n. for (elem = 1; elem n; elem++) pop (s); i = pop (s); 2. Use the operations push, pop, peek and empty to construct an operation which sets i to the bottom element of the stack, leaving the stack unchanged. (hint: use an auxiliary stack.) (STACK s1, s2) while (!empty (s1)) { h = pop (s1); push (s2, h); } i = h; while (!empty (s2)) { h = pop (s2); push (s1, h); } b) Use the operations push, pop, peek and empty to construct an operation which sets i to the third element from the bottom of the stack. The stack may be left changed. (STACK s1, s2) while (!empty (s1)) { h = pop (s1); push (s2, h); } for (elem = 1; elem = 3; elem++) i = pop (s2); /* i will exit loop with value of 3rd element from bottom of s1, the original stack */

Meer zien Lees minder
Instelling
Vak

Voorbeeld van de inhoud

Assignment 2 – Stacks

Write pseudo-code not Java for problems requiring code. You are responsible for the
appropriate level of detail.

1. a) Use the operations push, pop, peek and empty to construct an operation which sets i to
the second element from the top of the stack, leaving the stack unchanged.

h = pop (s);
i = pop (s);
push (s, i);
push (s, h);

b) Use the operations push, pop, peek and empty to construct an operation which sets i to
the nth element from the top of the stack, leaving the stack without its top n elements. You are
given integer n.

for (elem = 1; elem < n; elem++)
pop (s);
i = pop (s);

2. Use the operations push, pop, peek and empty to construct an operation which sets i to the
bottom element of the stack, leaving the stack unchanged. (hint: use an auxiliary stack.)
(STACK s1, s2)
while (!empty (s1)) {
h = pop (s1);
push (s2, h);
}
i = h;
while (!empty (s2)) {
h = pop (s2);
push (s1, h);
}

b) Use the operations push, pop, peek and empty to construct an operation which sets i to
the third element from the bottom of the stack. The stack may be left changed.
(STACK s1, s2)
while (!empty (s1)) {
h = pop (s1);
push (s2, h);
}
for (elem = 1; elem <= 3; elem++)
i = pop (s2);
/* i will exit loop with value of 3rd element from bottom
of s1, the original stack */

, 3. Simulate the action of the algorithm for checking delimiters for each of these strings by
using a stack and showing the contents of the stack at each point. Do not write an algorithm.

a) {[A+B]-[(C-D)]




b) ((H) * {([J+K])})




4. Write an algorithm to determine whether an input character string is of the form

xCy

where x is a string consisting only of the letters ‘A’ and ‘B’ and y is the reverse of the x (i.e. if
x=”ABABBA” then y must equal “ABBABA”). At each point you may read only the next
character in the string, i.e. you must process the string on a left to right basis. You may not use
string functions.

while (char != C) {
push (stack, char);
char = nextchar;

Geschreven voor

Vak

Documentinformatie

Geüpload op
29 januari 2023
Aantal pagina's
8
Geschreven in
2022/2023
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

$8.49
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
ExamsConnoisseur Self
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
587
Lid sinds
3 jaar
Aantal volgers
344
Documenten
1492
Laatst verkocht
3 weken geleden

4.2

68 beoordelingen

5
40
4
11
3
13
2
1
1
3

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen