Transition to the next class - Data Structures


If you are continuing on your journey in Computer Science, here are some suggestions for you.

  • The next class in the sequence will introduce you to completely new concepts, building on the concepts learnt in this class.

  • Make sure you are very comfortable with the concepts we learnt here. Review labs and homeworks, make sure you can solve them pretty easily.

  • Install a working environment in C++, which is the language you will be using in the next class.

  • Review C++ syntax before you take your next class. Make sure you develop:

    • Skills to solve the CS-1 level problems in C++.
    • Skills to debug C++ programs.

    Students who wrote basic C++ programs over the break did well in Data Structures. It also helps solidify your algorithmic problem solving skills.

  • You can also review the first few labs in Data Structures if you wish and work on those in advance:

In this document, there are some suggestions to help you get ready for your next class.

Learning C++

You are not learning C++ from scratch. Many basic constructs are very similar in C++, but there are differences too. Here are some sources that were highly recommended:

Go through the tutorial and the videos. Make sure to write many programs.

Differences between Python and C++

Here are a few first things to notice between the two:

  • C++ is a compiled statically typed language. This means that variables need to be defined with a data type first, and the data type cannot be changed.
  • Programs cannot be run until compiled. If you have a syntax error, the compiler will not produce an executable until you resolve all syntax errors.
  • In C++, many new errors will be checked at compile time, like trying to add a string and an integer. As Python is dynamically typed, you are used to resolving such errors at run time. This means, you will spend more of your time in fixing compilation errors in C++ than in Python. Hence, learn to write programs in small steps, test and expand.
  • Syntax differences: each line in a program must end with a semicolon and each block must be delimited by curly brackets.
  • Be aware of the scope of local/global variables. Generally using our convention of passing variables to functions only as arguments and returning the result will help you a lot.
  • Strings and a single character are the same type of object in Python, but not in C++. Overall, make sure you understand each data type well first. Start with simple data types before you go into containers.
  • Many basic programming constructs are similar: variables, data types, operations, operator precedence, functions, loops, files, etc. You will find that for loops generally involve a single integer counter, no range function. Learn the basic snytax for these first.
  • Containers will be different. Instead of lists in Python that can be used for everything, you will need to learn about arrays, lists and vectors in C++. All containers we used had flexible length, while in C++, some will have predefined size.
  • You will see classes in C++ are very similar, but have a few new limitations like private attributes that can only be used within the class. This is actually a good thing, believe me.

For more in depth description of the differences see:

Setting up your C++ Working Environment

Your basic development environment in C++ consists of an editor for writing programs and a Terminal window for compiling and running your programs.

  • You must have a C++ compiler installed. In Windows, the compiler comes with Cygwin. In Macs, you must install the Command line tools (which we have already done for our class).

  • You must open a Terminal window: Terminal under Applications->Utilities in Macs (black box) and Cygwin under PCs. See more about Cygwin below.

  • Navigate the terminal to the folder in which you have your program. See basic terminal commands below.

  • You must use an editor to write your programs. Many choices exist. The choice of editor is not so important, but becoming proficient in using an editor is.

  • Example editors (Google the name for your operating system):

    • Emacs
    • Sublime
    • Notepad++
    • Vim

    Some of these already come with the Cygwin installation, see below.

Basic Terminal Operations

Basic terminal operations (Terminal in Macs and Cygwin in PCs) include:

  • Displaying the current working directory the terminal is pointing to:

    $ pwd
  • Listing the files in the current working directory for the terminal:

    $ ls
    $ ls p*   ##lists files that start with p
    $ ls Dropbox   ## lists files in the directory Dropbox
                 ## (assuming it is one level below it)
  • Changing the working directory to a directory on your file system (cd means change directory):

    $ cd directory_name
    $ cd directory1/directory2   ## if you want to change multiple
                               ## levels of directory in a single step
    $ cd ..  ## goes one level up in the dictionary hierarchy
  • Compile code:

    $ g++ programname -o outputname

    For example:

    $ g++ -o program

    This generates a new file called program in Macs and program.exe in PCs.

  • To run a program called program, use:

    $ ./program
  • Create a symbolic link (a shortcut) between two folders is very good way to simplify your life. Suppose you are at your own Desktop. I will create a shortcut to a directory on my dropbox on my own Desktop:

    $ pwd
    $ ln -s /Users/sibeladali/Dropbox/CSCI1100_Fall2014/ cs1

This tells me to create a symbolic link (ln -s) for directory /Users/sibeladali/Dropbox/CSCI1100_Fall2014/ and call it cs1. Now, I can simply write the following:

$ cd cs1

Installing Cygwin

If you are using Windows, you should install Cygwin which comes with many things you need.

  1. Visit and download either the setup-x86 for 32-bit systems or setup-x86_64 for 64-bit systems. Most of you will use the 64-bit version.

  2. Save the executable somewhere you can easily access. Run the installer.

  3. Navigate through the installer. It is easiest if you leave all options as the default. When you get to the window of mirrors select one and click Next.

    1. PLEASE NOTE: It is possible that a mirror will be offline and you will have to re-run the installer.
  4. Install the following packages. To install, use the search function to find the package. To mark a package for installation click on Skip and it will change to a version number.

    1. G++ - Listed under Devel, second option down. The package is gcc-g++: GNU Compiler Collection (C++) Make sure Skip is now 4.8.3-X.
    2. GDB - Listed under Devel, last option. The package is gdb: The GNU Debugger.
    3. Zip - Listed under Archive, second to last option. The package is zip: Info-ZIP compression utility
    4. If you want an editor (I suggest you have one) add either Emacs or VIM. It is personal preference on which you want to try. Steps to install are identical to the above. They will be under Editors.
  5. Once all the packages you want are selected click next and make sure the box to Select Required Packages is CHECKED. Click Next and Cygwin will begin installing the packages.

    PLEASE NOTE: This step can take a long time.

#. Cygwin is now installed with the packages. If you ever need to uninstall or install new packages just re-run the setup.exe and modify as you need.

Using Cygwin

  • When you open a Cygwin window, it does not yet point to a valid location on your hard drive. The first thing you should do is to point it to your C drive with:

    $ cd c:
  • Next, you must point it to the root directory for all your files. In Windows, this is usually something like:

    $ cd c:/Users/your-user-name/

    Here you should be able to see folders like Desktop and Documents.

Integrated Development Environments (IDE)

As we used Wing for CS-1 as an integrated environment for Python, many IDEs exist for C++. Many general purpose IDEs work for C++ well:

Remember: IDEs are useful for debugging with a graphical user interface. But, it is likely that no one will be an expert in the specific IDE you use. Practice and learn its features before starting to use it in class assignments.

Final Note

Please feel free to send me other resources and corrections to this document by email.