Thursday, December 24, 2009

C++ using STL some coding?

The functions push_front( ) and pop_front( )


modify the first element in the list. Similarly push_back( ) and pop_back( )


functions deal at the back of the list. The function sort( ) is used to sort the list.


Write a program using these functions to do the following operations:





(i) Create a list of 8 integers (15, 8, 20, 45, 7, 2, 50, 10)


(ii) Display the size and the elements of the list


(iii) Delete first and last elements from the list


(iv) Display the size and rest of the elements


(v) Sort the list and display the resulting list.








#include%26lt;iostream%26gt;


#include%26lt;list%26gt; // For list%26lt;T%26gt; class


#include%26lt;algorithm%26gt; // For reverse( ) function


using namespace std;


void main( ) {


list%26lt;int%26gt; nums;


list%26lt;int%26gt;::iterator iter;


int number;


cin %26gt;%26gt; number;


while (number != -9999)


{


nums.push_back(number);


cin%26gt;%26gt; number;


}


for (iter = nums.begin( ); iter != nums.end( ); iter++)


cout %26lt;%26lt; *iter %26lt;%26lt;endl;


reverse(nums.begin( ), nums.end( ));


for (iter = nums.begin( ); iter != nums.end( ); iter++)


cout %26lt;%26lt; *iter %26lt;%26lt;endl;C++ using STL some coding?
What's your question? The code doesn't seem to have any obvious bugs. Doesn't look like it'll do what the problem description says to do, but that's not something we can help you with.





Sorry.
  • hair shampoo
  • printer toner
  • triamcinolone cream
  • palm oil
  • No comments:

    Post a Comment