CS35: Data Structures and Algorithms

Lab 05 Notes

Lab 05 Agenda

Clone lab05

This is the same as previous labs. Remember to run ssh-add when you log in, so you don't get repeatedly asked for you ssh password. Go to the CS35 github org, to find the clone link for your repo on the web interface.
$ cd ~/cs35/labs
$ git clone <link you got from github> ./lab05
You should also update your examples repository by going in your examples directory and pulling the updated version of the repository
$ cd ~/cs35/examples/
$ git pull

Setup Symbolic Link

Just like in previous labs, we establish a symbolic link to a shared directory that contains files to test your program. You can create the link by executing the following commands:
$ cd ~/cs35/labs/lab05
$ ln -s /usr/local/doc/lab05-data/ ./test_data

Note the path /usr/local/doc/lab05-data/ is local only to the machines on the CS network and will not work if you clone your code to your personal computer.

2D Arrays

We will first have a look at a few slides describing how to allocate an use 2D arrays. Then we will complete a few exercise in the ~/cs35/examples/week-06/2Darray folder.

Week 07

Quiz review

int max100top(int* nums, int size){
  int ans=101;
  for( int i=0; i<size; i++){
    if(nums[i] <=100){
      if( (ans==101) || (nums[i] > ans) ){
         ans = nums[i];
      }
  }
  return ans;
}

more examples

$ cd ~/cs35/examples/
$ git pull

Tia's gdb links

How to use gdb

Sample sessions

The above examples use C, but the program is mostly the same in cpp aside from some minor name changes for filename extensions, include headers, and compiler used. The cpp examples are in ~/cs35/examples/week-07/gdb/

Valgrind examples

See ~/cs35/examples/week-07/valgrind/
$ make
$ valgrind ./simpletest

Lab 05

That's it for in lab exercises. Hop over to the Lab 05 Writeup to begin the lab.