MESSAGE
DATE | 2015-02-27 |
FROM | Ruben Safir
|
SUBJECT | Subject: [LIU Comp Sci] Allorithms Midterm
|
From owner-learn-outgoing-at-mrbrklyn.com Fri Feb 27 15:32:49 2015 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix) id EC86A1612E6; Fri, 27 Feb 2015 15:32:48 -0500 (EST) Delivered-To: learn-outgoing-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 28) id D8CBA1612F7; Fri, 27 Feb 2015 15:32:48 -0500 (EST) Delivered-To: learn-at-nylxs.com Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) by mrbrklyn.com (Postfix) with ESMTP id 475901612E6 for ; Fri, 27 Feb 2015 15:32:47 -0500 (EST) Received: from [10.0.0.19] (unknown [96.57.23.82]) by mailbackend.panix.com (Postfix) with ESMTPSA id 51C4E103FF for ; Fri, 27 Feb 2015 15:32:47 -0500 (EST) Message-ID: <54F0D46F.4-at-panix.com> Date: Fri, 27 Feb 2015 15:32:47 -0500 From: Ruben Safir User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: learn-at-nylxs.com Subject: [LIU Comp Sci] Allorithms Midterm Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: owner-learn-at-mrbrklyn.com Precedence: bulk Reply-To: learn-at-mrbrklyn.com
Anyone notice this question, aside from having at least one typo, is an infinite loop?
Question 11
~~~~~~~~~~~~~
What get's printed by the following code?
stack stk;
queue q;
stk.push(10);
stkt.push(20);
stk.push(30);
stk.push(40);
q.push(50);
q.push(60);
while (stk.top( ) != 10) {
q.push(stk.top());
stk.pop();
}
while( q.front( ) != 30 ) {
stk.push(q.front());
q,pop( );
}
while ( ! stk,empty( ) ) {
cout << stk.top(0 << " ";
}
cout << endl;
while ( !q.empty( ) ) {
cout << q.front( ) << " ";
}
cout << endl;
a.
10 20 30 40
50 60
b.
40 60 50 10
30 20 c.
40 30 20 10
50 60 d.
10 50 60 70
20 30
~~~~~~~~~~~~~~~~~~~~~` test code
#include #include #include
using namespace std;
int main(int argc, char * argv[]){ stack stk;
queue q;
stk.push(10);
stk.push(20);
stk.push(30);
stk.push(40);
q.push(50);
q.push(60);
while (stk.top( ) != 10) {
q.push(stk.top());
stk.pop();
}
while( q.front( ) != 30 ) {
stk.push(q.front());
q.pop( );
}
while ( ! stk.empty( ) ) {
cout << stk.top() << " ";
}
cout << endl;
while ( !q.empty( ) ) {
cout << q.front( ) << " ";
}
cout << endl;
return 0;
|
|