October 17, 2013

Matt finished the make file for our stack program. Matt's code is included at the bottom of this entry. Information on Make files can be found here. To use Matt's Make file:

On a lab46 terminal:

$ cd /var/public/data/fall2013/linkedlistimp

Then copy the contents of the directory:

$ make copy
$ cp -a ~/src/dir

In Matt's Make file:

To use Matt's Make file:

  1. $ make

  2. $ ls lib

    Shows the newly made .lib files.

  3. $ make clean

    Removes all the object files.

  4. $ make debug

    Builds the source code with debugging symbols. Not required but good practice; can also use “make”.

  5. The terminal output for Matt's Make file:

    lab46:~/src/datas/linkedlistimp$ make
    make[1]: Entering directory `/home/nbrimme1/src/datas/linkedlistimp/src'
    make[2]: Entering directory `/home/nbrimme1/src/datas/linkedlistimp/src/list'
    [L]                        ... SUCCESS
    make[2]: Leaving directory `/home/nbrimme1/src/datas/linkedlistimp/src/list'
    
    make[2]: Entering directory `/home/nbrimme1/src/datas/linkedlistimp/src/node'
    [B]   cp.c                 ... OK
    [B]   mk.c                 ... OK
    [B]   rm.c                 ... OK
    [L]                        ... SUCCESS
    make[2]: Leaving directory `/home/nbrimme1/src/datas/linkedlistimp/src/node'
    
    make[2]: Entering directory `/home/nbrimme1/src/datas/linkedlistimp/src/stack'
    [B]   peek.c               ... peek.c: In function 'peek':
    peek.c:6: warning: control reaches end of non-void function
    OK
    [B]   pop.c                ... OK
    [B]   push.c               ... OK
    [B]   stackops.c           ... OK
    [L]                        ... SUCCESS
    make[2]: Leaving directory `/home/nbrimme1/src/datas/linkedlistimp/src/stack'
    
    
    make[1]: Leaving directory `/home/nbrimme1/src/datas/linkedlistimp/src'
    
    
    lab46:~/src/datas/linkedlistimp$ ls lib
    liblist.a  libnode.a  libstack.a
    lab46:~/src/datas/linkedlistimp$ make clean
    make[1]: Entering directory `/home/nbrimme1/src/datas/linkedlistimp/src'
    make[2]: Entering directory `/home/nbrimme1/src/datas/linkedlistimp/src/list'
    rm -f *.o  core
    make[2]: Leaving directory `/home/nbrimme1/src/datas/linkedlistimp/src/list'
    make[2]: Entering directory `/home/nbrimme1/src/datas/linkedlistimp/src/node'
    rm -f *.o cp.o mk.o rm.o core
    make[2]: Leaving directory `/home/nbrimme1/src/datas/linkedlistimp/src/node'
    make[2]: Entering directory `/home/nbrimme1/src/datas/linkedlistimp/src/stack'
    rm -f *.o peek.o pop.o push.o stackops.o core
    make[2]: Leaving directory `/home/nbrimme1/src/datas/linkedlistimp/src/stack'
    make[1]: Leaving directory `/home/nbrimme1/src/datas/linkedlistimp/src'
    make[1]: Entering directory `/home/nbrimme1/src/datas/linkedlistimp/testing'
    rm -f *.o stacktest core
    make[1]: Leaving directory `/home/nbrimme1/src/datas/linkedlistimp/testing'
    lab46:~/src/datas/linkedlistimp$ make debug
    make[1]: Entering directory `/home/nbrimme1/src/datas/linkedlistimp/src'
    make[2]: Entering directory `/home/nbrimme1/src/datas/linkedlistimp/src/list'
    ar rcs ../../lib/liblist.a 
    make[2]: Leaving directory `/home/nbrimme1/src/datas/linkedlistimp/src/list'
    
    make[2]: Entering directory `/home/nbrimme1/src/datas/linkedlistimp/src/node'
    gcc -Wall -I ../../inc  -DDEBUG -g -c cp.c
    gcc -Wall -I ../../inc  -DDEBUG -g -c mk.c
    gcc -Wall -I ../../inc  -DDEBUG -g -c rm.c
    ar rcs ../../lib/libnode.a cp.o mk.o rm.o
    make[2]: Leaving directory `/home/nbrimme1/src/datas/linkedlistimp/src/node'
    
    make[2]: Entering directory `/home/nbrimme1/src/datas/linkedlistimp/src/stack'
    gcc -Wall -I ../../inc  -DDEBUG -g -c peek.c
    peek.c: In function 'peek':
    peek.c:6: warning: control reaches end of non-void function
    gcc -Wall -I ../../inc  -DDEBUG -g -c pop.c
    gcc -Wall -I ../../inc  -DDEBUG -g -c push.c
    gcc -Wall -I ../../inc  -DDEBUG -g -c stackops.c
    ar rcs ../../lib/libstack.a peek.o pop.o push.o stackops.o
    make[2]: Leaving directory `/home/nbrimme1/src/datas/linkedlistimp/src/stack'
    
    
    make[1]: Leaving directory `/home/nbrimme1/src/datas/linkedlistimp/src'
    
    
    lab46:~/src/datas/linkedlistimp$


Matt's Code:

I'm finding that GDB is quickly becoming an indispensable and invaluable tool when finding and fixing bugs. The command alias gcc='gcc -g' won't negatively effect anything in the future, so I'll make it an alias. Also, Google has some nice GDB “cheat sheets” that will come in handy.

I had the idea to use 2 lists instead of modifying just 1. My logic is complicated and that logic seems far more simpler; and hopefully simpler to implement.

Pseudocode/Logic steps:

  1. Create 2 lists: (Not sure this will work; Could copy tmp's list into tmp2's list, then call clearList() on tmp2?).
    1. tmp → unsorted list.
    2. tmp2 → sorted list.
  2. Find the lowest value in tmp's list
  3. Insert that value into tmp2's list
  4. Remove the lowest value from tmp's list
  5. Repeat steps 2-4 until the program is at the end of the tmp's list.
    1. Not sure if this is needed; delete empty tmp list?
  6. Display tmp2's sorted list.

Back to my Opus