Comp151: Lab03

Objective:  

global objects and functions

pointers

introduction to a debugger

@

Download

LinkedList

Transpose

AssesmentTask

@

Reference

Data Display Debugger

search in google

@

Lab Work

Create directories  "linkedlist" and "transpose" and "task" under ~/comp151/lab03

Download the zip files to the corresponding folder

unzip the file using command "unzip"
   
      e.g., unzip LinkedList.zip

@

List-Accessing Problem

In this problem we are given a linked list of city names

and a sequence of requested accesses :Sydney, Rome, Rome, Rome, Rome, HongKong, Moscow, ... ...

The cost of accessing city is the number of cities that have to be traversed to get to that city. Given a sequence of   requested accesses, our objective is to minimize the cost of accessing the cities in the sequence in the given order.

While processing the accesses we are allowed to modify the list as follows: after accessing a city in the list, we can move it anywhere we want that is closer to the front of the list.

@

Some algorithms for the problem

LinkedList  
        -- Never modify the list

Transpose
        --After accessing city 'A', move city 'A' one unit forward towards the front of the list
        --e.g. after accessing Sydney, the list becomes

@

@

LinkedList

        --compile LinkedList using the command "gmake"
        --run the program
        --"access.txt" contains a sequence of requested accesses

@

        --notice how "extern" in main.cpp is used to access the global objects and function.
       
--notice how cities are inserted into the list

@

Transpose

        --List::Insert is now public so as to insert node at run time

        --List::Delete added to delete node at run time

        --compile the program

        --when you run the program, it hangs.

       Let's figure out what happened using the debugger 'ddd'

       -- notice the '-g' parameter in g++

       -- what is memory leak?

    -- what is dangling pointer?

Assessment Task

  Go to the "task" directory in  List.cpp file and complete the implementation  of the functions:
    int length();
and   void insert_after_index(string targetCity,int  index);
          

        add your student name, student id, email, and lab section in the very beginning of the file as a comment
          
          place your work

            main.cpp
            List.h
            List.cpp
            resource.h
            resource.cpp
            city.txt
   
     Makefile

        under ~/comp151/lab03/task

@

Submission

Our system will collect the files stored under ~/comp151/lab03/task at midnight of the day of your lab.