// C++ program to demonstrate the use of list containers #include #include using namespace std; int main() { // defining list list list1 ; list list2 ; for( int i1=5 ; i1 >= 1 ; i1-- ) { list1.push_back( i1 ) ; } list1.push_back( 16 ) ; list::iterator it = list1.begin() ; list::iterator it2 = list2.begin() ; list2.push_back( *it ) ; cout << "--------" << endl ; for( int a1 : list1 ) { cout << a1 << " " ; } cout << endl ; for( int a1 : list2 ) { cout << a1 << " " ; } cout << endl ; cout << "-------------" << endl ; //if ( 1 == 1 ) return 1 ; int count = 0 ; for( it++ ; it != list1.end() ; it++ ) { int x1 = *it ; cout << x1 << endl ; bool position_found = false ; for( it2 = list2.begin() ; it2 != list2.end() ; it2++ ) { if ( x1 < *it2 ) { list2.insert( it2 , x1 ) ; position_found = true ; // cout << "Step 0: " << *it2 << endl ; break ; } // cout << "Step 1: " << *it2 << endl ; // if ( count++ > 5 ) break ; } //for if ( !position_found ) { list2.push_back( x1 ) ; } //cout << "Step 2: " << x1 << endl ; } //for cout << "--------" << endl ; for( it2 = list2.begin() ; it2 != list2.end() ; it2++ ) { int x1 = *it2 ; cout << x1 << endl ; } return 0; }