User Tools

Site Tools


opus:fall2013:jserosky:start

Justin Serosky's fall 2013 Opus

CSCS 2320

Introduction

My name is Justin Serosky. I like to play video games and tennis. This is my third year at CCC, and also my last semester.

Data Structures Journal

Sep 4, 2013

Typedef struct person Person makes “Person People[8]” equivalent to “struct person People[8]”

October 17, 2013

Struct: A datatype that has datatypes inside of it.

struct node {
        int value;
        struct node *next;
        struct node *prev;
};

To create a struct you need to allocate memory that is the size of the struct and set the datatype of that to a struct pointer:

temp=(Node*)malloc(sizeof(Node));

Singly linked list: A list which has nodes that can only point next.

Doubly linked list: A list which has node that can point next or previous.

Functions that take a double pointer to a struct need to take the address of the struct pointer.

temp=(Node*)malloc(sizeof(Node));
Remove(List *, Node **);
myList=Remove(myList, &temp);

To deallocate a node you need to use:

free(node);

October 23, 2013

Got my sort function to finally work. I did this by going through the list until the highest value is assigned to a node “highest” and then removed that node from the list. I then created a second list to insert the highest node into. I did this over and over, picking up the next highest node from the list and doing the same thing, until it got to the lowest value. I also made it so if the second list is null, then the first node to go from the first list to the second would set the second list's start and end to that node after removing it from the first list. The for loop starts and 0 and goes through for however big the size of the list is. Here's the loop that does this:

1
for(i=0; i < x;i++)
{
                temp=myList->start;
                highest=myList->start;
                while(temp != NULL)
                {
                        if(highest -> value < temp -> value)
                        {
                                highest=temp;
                                temp=myList->start;
                        }
                        else
                        {
                                temp=temp -> next;
                        }
                }
                myList=Remove(myList, &highest);
                if(myList2->start==NULL)
                {
                        myList2 -> start = myList2 -> end = highest;
                }
                else
                {
                        myList2=Insert(myList2, myList2 -> start, highest);
                }
}

October 24, 2013

The arrow used in Struct pointers is actually the same as dereferencing the struct, then doing a dot at the end followed by the variable inside the struct. For example:

Struct person{
     int age;
};
Struct person* man;
man -> age = (*man).age

Here's an easy way to set a variable with datatype of a struct:

Struct person{
     int age;
} man;

November 6, 2013

Bitree and stuff.

November 22, 2013

Finished my buildtree function, just trying to get the display to work. Put an else statement in the build tree which will omit duplicate values. Added breaks to my ifs and elses to make sure it didn't infinitely loop. Played some Tom's mom tic-tac-toe. Worked on re-implementing my doubly linked lists, structs, and queues (also nodes) in C++. Any calls to private variables must be in the form of a function if outside the class. When getting a value, return a pointer, when setting the value, input the value and set it and return void.

December 4, 2013

Learned a few things over the past week or two. If you include iostream.h you can use std::sort(arraystart, arrayend) to sort an array of values. Also, including algorithms.h will allow you to use next_permutation:

do {
                for(i=0;i<= (this->setlngth)-1;i++)
                {
                        printf("%d ", this->sett[i]);                   //this prints the set
                }
                printf("\n");
} while ( std::next_permutation(this->sett,(this->sett)+setlngth) );  

next_permutation also takes the inputs as beginning of array and end of array, respectively. This is being used inside an object so sett is the object's private set and setlngth is the object's set's length. This will print out all of the permutations of the set. Also, stackoverflow is quite helpful when looking for examples/answers to questions.

December 8, 2013

So this happened:

lab46:~/src/datastructs/oop_reimp/testing$ ./stacktest
3
4
5


linked list has 0 nodes
*** glibc detected *** ./stacktest: double free or corruption (fasttop): 0x00000000024060a0 ***
======= Backtrace: =========
/lib/libc.so.6(+0x71e16)[0x7fb714636e16]
/lib/libc.so.6(cfree+0x6c)[0x7fb71463bb8c]
./stacktest[0x400a82]
/lib/libc.so.6(__libc_start_main+0xfd)[0x7fb7145e3c8d]
./stacktest[0x4007f9]
======= Memory map: ========
00400000-00402000 r-xp 00000000 00:11 2147817070                         /home/jserosky/src/datastr                esting/stacktest
00601000-00602000 rw-p 00001000 00:11 2147817070                         /home/jserosky/src/datastr                esting/stacktest
02406000-02427000 rw-p 00000000 00:00 0                                  [heap]
7fb710000000-7fb710021000 rw-p 00000000 00:00 0
7fb710021000-7fb714000000 ---p 00000000 00:00 0
7fb7145c5000-7fb71471e000 r-xp 00000000 ca:01 57476                      /lib/libc-2.11.3.so
7fb71471e000-7fb71491d000 ---p 00159000 ca:01 57476                      /lib/libc-2.11.3.so
7fb71491d000-7fb714921000 r--p 00158000 ca:01 57476                      /lib/libc-2.11.3.so
7fb714921000-7fb714922000 rw-p 0015c000 ca:01 57476                      /lib/libc-2.11.3.so
7fb714922000-7fb714927000 rw-p 00000000 00:00 0
7fb714927000-7fb71493d000 r-xp 00000000 ca:01 57346                      /lib/li
7fb71493d000-7fb714b3c000 ---p 00016000 ca:01 57346                      /lib/li
7fb714b3c000-7fb714b3d000 rw-p 00015000 ca:01 57346                      /lib/li
7fb714b3d000-7fb714bbd000 r-xp 00000000 ca:01 57575                      /lib/li
7fb714bbd000-7fb714dbd000 ---p 00080000 ca:01 57575                      /lib/li
7fb714dbd000-7fb714dbe000 r--p 00080000 ca:01 57575                      /lib/li
7fb714dbe000-7fb714dbf000 rw-p 00081000 ca:01 57575                      /lib/li
7fb714dbf000-7fb714eb5000 r-xp 00000000 ca:01 108139                     /usr/li
7fb714eb5000-7fb7150b5000 ---p 000f6000 ca:01 108139                     /usr/li
7fb7150b5000-7fb7150bc000 r--p 000f6000 ca:01 108139                     /usr/li
7fb7150bc000-7fb7150be000 rw-p 000fd000 ca:01 108139                     /usr/li
7fb7150be000-7fb7150d3000 rw-p 00000000 00:00 0
7fb7150d3000-7fb7150f1000 r-xp 00000000 ca:01 57433                      /lib/ld
7fb7152dc000-7fb7152e0000 rw-p 00000000 00:00 0
7fb7152ec000-7fb7152f0000 rw-p 00000000 00:00 0
7fb7152f0000-7fb7152f1000 r--p 0001d000 ca:01 57433                      /lib/ld
7fb7152f1000-7fb7152f2000 rw-p 0001e000 ca:01 57433                      /lib/ld
7fb7152f2000-7fb7152f3000 rw-p 00000000 00:00 0
7fff2642d000-7fff26442000 rw-p 00000000 00:00 0                          [stack]
7fff2654f000-7fff26550000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsysca
String is: 4Aborted
lab46:~/src/datastructs/oop_reimp/testing$
lab46:~/src/datastructs/oop_reimp/testing$

MONTH Day, YEAR

This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.

As an aid, feel free to use the following questions to help you generate content for your entries:

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?
opus/fall2013/jserosky/start.txt · Last modified: 2014/01/19 02:56 by 127.0.0.1