Sign In | Subscribe

Enter your Sign on user name and password.

Forgot password?
  • Follow us on:
Start learning today, and be successful in your academic & professional career. Start Today!
Loading video...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Intermediate C++
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Related Services

Start Learning Now

Our free lessons will get you started (Adobe Flash® required).
Get immediate access to our entire library.

Sign up for

Membership Overview

  • Unlimited access to our entire library of courses.
  • Search and jump to exactly what you want to learn.
  • *Ask questions and get answers from the community and our teachers!
  • Practice questions with step-by-step solutions.
  • Download lesson files for programming and software training practice.
  • Track your course viewing progress.
  • Download lecture slides for taking notes.
  • Learn at your own pace... anytime, anywhere!

Containers, List

  • Since we'll need to confirm the contents of our list multiple times, it would be useful to create a function that does that. Write one that iterates through each element of a list<float> container passed in as a parameter and prints out the value of each element. Hint: iterators are declared in the particular container, e.g., for a container declared as list<float>, the declaration for its iterator will be list<float>::iterator. Optionally, also pass in a string text parameter to print out what is being confirmed.
  • Create a program that declares a list for 10 floats. Use the list constructor to initialize it so that each element is set to 3.14. Confirm that each element was properly set.
  • Modify the program to set each element to 0.0. Confirm the change.
  • Modify the program to add 10 new elements, starting with a value of 0.5, and each element after the first one is 0.5 greater than the previous element. E.g., add element 0.5, 1.0, 1.5, etc. Use the “push_back()” method. Confirm the change.
  • Modify the program to add another 10 new elements, starting with a value of -0.5, and each element after that is 0.5 smaller than the previous element. E.g., add elements -0.5, -1.0, -1.5, etc. Use the “push_front()” method. Confirm as always.
    • At this point, your output should read something like;
      -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0 0 0 0 0 0 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
  • Use the “remove_if()” method to remove every element with a value between -0.1 and 0.1. Confirm the results.
  • As it so happens, we’ve created a list that happens to already be sorted in ascending numerical order, so we don’t need to use the "sort()" method just now. Sorting large amounts of data can be time-consuming. We can avoid this so long as we always keep the list in order.
    • Modify your program to repeatedly ask the user for a number (stop looping when the user enters a 0.0). Insert this number into the list, but in the correct location in ascending numerical order. Confirm the results after the user is finished.
    • Hint: iterate through the list and inspect each element until you find an element value where the user’s input value is less.
  • Newsflash: we've just received a memo from the customer (You remember that guy, the one who pays our bills?) The list was supposed to be in descending numerical order, and he wants it yesterday. Rather than re-writing all the existing code, use the “reverse()” method after the insertions are completed.
  • Later, you can rewrite all the code if you have time.

Containers, List

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • Lesson Overview 0:13
  • Linked List Overview 1:34
    • Arrays and Vectors
    • Linked List
  • List Information 5:53
    • Empty Method
    • Max Size
    • Resize
  • List Access 7:48
    • Front and Back
    • Iterators
    • Example
  • List Iterators vs. Vector Iterators 9:24
    • The Next Element May be Physically in Memory Before the Current Element
    • Vector Iterators Allow Integer Add
    • List Iterators Do Not Allow Integer Add
  • Simple List Modification 14:24
    • Constructors
    • Difference Between Assign and Insert
    • Assign
    • Insert
    • Push
    • Pop
    • Erase
  • Complex List Modification 18:34
    • Merging and Splicing
    • Merge
    • Splice
    • Reordering
    • Removing
  • Modification Examples 23:22
  • Functions as Parameters 24:49
    • A Function for 'remove_it()'
    • A Function for Merge and Sort - Evens Before Odds
  • Deque 27:28
    • Insertion or Removal in Middle May be More Efficient than with Vectors
    • Not Guaranteed to be Contiguous Memory
    • Same Method as Vector, Plus More
  • Stack 29:11
    • Empty, Size, Top, Push, Pop
  • Queue 31:56
    • Definition
  • Not That Kind of List 33:19