{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Section7Problems 1

# Section7Problems 1 - CSE143 Section#7 problems problems For...

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE143 Section #7 problems problems For the fol-lowing you are using the Stack and eueue assume that interfaces and the ArrayStack and LinkedQueue implementations discussed in Lecture. As a result, values will be stored as Integer or Character objects rather than simple ints or chars. Each problem wil"l indicate what kind of you can use as auxiliary structure storage. You may not use any other auxJ-Iiary data structures problem, to sol-ve this you can have as many although simple variables as you l-ike. 1. Write a method splitstack that takes a stack containing a l-ist of integers j-nto negatives and that splits it and nonnegatives. The numbers in the stack should be rearranged so that all the negatj-ves appear on the bottom of the stack and aII the nonnegatives appear on the top of the stack. In other words, it after this method is ca1led you were to pop numbers off the stack, you would first get all the nonnegative numbers (at the top) and then get all the negative numbers (at the bottom) . It does not matter what order the numbers appear in as Iong as a1l- the negatives appear Lower in the stack than all you shouLd the nonnegatives. queue as auxilj-ary use a single storage to solve this problem. Method splitStack should take a single parameter: the stack to be split. 2. Write a method stutter that takes a stack containing a list that replaces every val-ue in the stack with 2 of that value. suppose the stack stores these values: bottom Then the [3, J, L, 14, store J, It 9] top these L, l-4, val-ues L4,9,9] after the top method terminates: of integers and For eiample, stack should bottom [3,3,7, you must preserve Notice that the original order. In the original List the 9 was at the top and woul-d have been popped first. In the new stack the two 9's would be the first vaLues popped from the stack. You should use Method stutter of integers to 3. queue as auxiliary a single storage shoul-d take a single parameter: the be stuttered. problem. to solve this stack containing the List Write a method copyStack that takes a stack containj-ng a list of integers as a parameter and that returns a reference to a copy of the original stick (i.e.' a new stack with the same values as the orj-ginal stored in the same order as the original) . Your method should create the new stack and fillit up with the sarne'-values that are-sEored-in the originaL staek. It shoule! return a reference to this new stack. You will be removing val-ues from the original stack to make the copy, but you have to be sure to put them back into the original stack in the same order before you are done. In other words, when your method is done executinq, the original stack wil-l be restored to its original state and you wil-l return a reference to a new independent stack that is in the same state. You should use one queue as auxiliary storage problem. to sol,ve this wil-L also have a second stack that you construct and return. Methoci copyStack should take a single parameter: the stack to be copied. you ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online