Lab 4: Vectors

Copy the files from ~cs102/robot_labs/Lab_Skeletons/Lab4/ to your Lab4 directory.

In this lab you will experiment with the basics of making and using vectors and then implement vectors in a simple algorithm.

Topics:

The main topics you may need in this lab are:

Part I: Vector Basics

Your job is to write a program in the file Vector.cpp that:

Remember:

Part II: Bubble Sort

For the second part of this lab you will write a function that will sort the elements of your vector from part one in ascending (counting up) or descending (counting down) order.. The algorithm that you will use to sort your vector with be an implementation of the Bubblesort method. The function should have the following prototype:

    vector<int> bubble_sort (vector<int> input, bool ascending);

This function should return a new vector, that is a sorted version of input in either ascending or descending order depending on the value of ascending. (i.e. if ascending == false then sort in descending order)

The sorting will be done using the BubbleSort algorithm, one of the simplist  algorithms to implement. 
Implement the algorithm from the following pseudocode:


Once you've done all of this, your program should be done. Make sure that your program runs exactly as the vector_example program provided.

Example Run:

If your input looks like this

10
0
1
3
4
6
8
7
9
2
5

Your ouput should look like this:

Input
0 1 3 4 6 8 7 9 2 5
Ascending
0 1 2 3 4 5 6 7 8 9
Decending
9 8 7 6 5 4 3 2 1 0

Part IV: Submission

As you may have noticed, this lab does not use your robot. This means two things: