# Q_A - KSU Faculty Member websites

Document Sample

```					                                             Test Paper

Data Structure
CS-217

MM: 15                                                                              Duration: 2Hour

Question 1.: - Answer any five                                                                    1x5

1). what will be the output of the following sample program?
int main()
{
stack< string, vector<string> > s;
s.push( "me" );
s.push( "talk" );
s.push( "to" );
while ( !s.empty() )
{
cout << s.top() << " ";
s.pop();
}
cout <<"\n\n\n";
return 0;
}
(A) to talk me       (B) me talk to         (C) talk to me           (D) Non
2). which is STL function?
(A) randd()          (B) binary()            (C) queue()              (D) Draw()

3). which is Heap function?
(A) Push_heap()      (B) Pop_heap()          (C) Del_heap()           (D) In_heap()

4). The Sort algorithm requires a _______ iterator?

5). The three STL container adapters are _____,_______ and ______?

6). STL algorithms are encapsulated as member functions within each container class (T/F)?

7). The five main iterator types are ____,____,____,____ and _____?

Question 2. Write any one (Data Structure) Program on system using C++.                           1x10

1). Write a program to reverse the given string “BELT”, Use reverse function on list and STL BASIC
hidden files “Algorithm”. The result should be “TLEB”.
2). Write a program to push 0,1,2,3,4,5,6,7,8,9 and pop 9,8,7,6,5,4,3,2,1,0 with for statement. Use Push
and Pop in a stack of list.
3). Write a program use binary_search to locate a value in a vector. The given value is 10, 2, 17, 5, 16, 8,
13, 11, 20, 7.
Test Paper

Data Structure
CS-217

MM: 15                                  Answer Sheet                        Duration: 2Hour

Question 1.: - Answer any five

1) (B) me talk to
2) (B) binary()            (C) queue()
3) (A) Push_heap()         (B) Pop_heap()
4) Random Access.
5) Stack. Queue and Priority_Queue.
6) False, STL algorithms are not member functions. They operate indirectly on containers through
iterator.
7) Input, Output, forward, bidirectional and random access.

Question 2. Write any one (Data Structure) Program on system using C++.

1) /* Write a program to reverse the given string “BELT”, Use reverse function on list and STL
BASIC hidden files “Algorithm”. The result should be “TLEB”. */
2) #include <iostream>
3) #include <cassert>
4) #include <list>
5) #include <string>
6) #include <algorithm> // that is for reverse
7) using namespace std;
8) int main()
9) {
10) string s("BELT");
11) list<char> list1(s.begin(), s.end());
12) list<char>::iterator i;
13) for (i = list1.begin(); i != list1.end(); ++i)
14) cout << *i;
15) reverse(list1.begin(), list1.end());
16) for (i = list1.begin(); i != list1.end(); ++i)
17) cout << *i;
18) return 0;
19) }

1) /* Write a program to push 0,1,2,3,4,5,6,7,8,9 and pop 9,8,7,6,5,4,3,2,1,0 with for statement.
Use Push and Pop in a stack of list. */
2) #include <iostream>
3) using std::cout;
4) using std::endl;
5) #include <stack> // stack adapter definition
6) #include <vector> // vector class-template definition
7) #include <list> // list class-template definition
8)    int main()
9)    {
10)     // stack with underlying list
11)     std::stack< int, std::list< int > > intListStack;
12)   cout <<"\n\n";
13)     for ( int i = 0; i < 10; i++ )
14)     {
15)       intListStack.push( i );
16)       cout << "\nPushing: "<< intListStack.top();
17)     }
18)
19)   cout <<"\n\n";
20)     while ( !intListStack.empty() )
21)     {
22)       cout << "\nTopping: "<<intListStack.top();
23)       intListStack.pop();
24)     }
25)   cout <<"\n\n";
26)     return 0;
27)   }

1) /* Write a program use binary_search to locate a value in a vector. The given value is 10, 2, 17,
5, 16, 8, 13, 11, 20, 7. */
2) #include <iostream>
3) using std::cout;
4) using std::endl;
5)
6) #include <algorithm>
7) #include <vector>
8) #include <iterator>
9)
10) int main()
11) {
12) int a[ 10 ] = { 10, 2, 17, 5, 16, 8, 13, 11, 20, 7 };
13) std::vector< int > v( a, a + 10 ); // copy of a
14) std::ostream_iterator< int > output( cout, " " );
15)
16) cout << "Vector v contains: ";
17) std::copy( v.begin(), v.end(), output ); // display output vector
18)
19) // locate first occurrence of 16 in v
20) std::vector< int >::iterator location(); //location in place of location()
21) // use binary_search to locate 13 in v
22) if ( std::binary_search( v.begin(), v.end(), 13 ) )
23)     cout << "\n\n13 was found in v";
24) else
26)
27)
28) cout << endl;
29) return 0;
30) }

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 7 posted: 12/19/2011 language: pages: 3