COP+2220

=COP2220=

Focus:
 * Data structures
 * Pointers
 * Recursion

=Pointers=

A point is initialized in c using the asterisk(*) symbol when you declare your variable(type *ptrName). The pointer 'points' to the the location in memory of the type specified by address. You can access the variable at the pointers location by using an asterisk before the pointers name. The location the pointer 'points' to can be changed by assigning the pointer to a new address by using the ampersand(&) symbol in front of a variable of the pointers type. Pointers are the base of many data structures such as linked lists and binary trees, as well as quickly iterating through arrays.

Examples:
 * Initialization
 * [[file:ptr1.cpp]]
 * Iteration through arrays
 * [[file:StringFind.cpp]]
 * [[file:StringFindFunction.cpp]]
 * Linked lists
 * [[file:structPointer.cpp]]
 * [[file:LinkedList2.cpp]]

=Recursion=

A recursive function is basically a function that calls itself. An easy example of recursion is when two mirrors are set parallel to each other and the nested images are a form of infinite recursion. When we implement our recursive functions we will avoid this type of infinite loop. Recursion can be incredibly useful to make very complicated code or repetitious code much shorter. It can be used to output the Fibonacci sequence, factorials, iterating through linked lists, and even solving the Tower of Hanoi.

Examples:
 * [[file:factorial.cpp]]
 * [[file:fibonacci.cpp]]
 * [[file:towerOfHanoi.cpp]]
 * [[file:hopScotch.cpp]][[file:hopScotchWorking.cpp]]

=Data Structures=

LinkedList
A linked list is basically a struct with one or more pointers to other structs of the same type. A linked list keeps track of the start and end object of the list.

Examples:
 * [[file:LinkedList2.cpp]]
 * [[file:structPointer.cpp]]

Stack
A stack is a linked list that only keeps track of the start and keeps building on top of it. Stacks

Queue
A queue is a list that can only read off the top and add to the end. Queue

Binary Tree
A binary tree is when your linked list contains two pointers to the data type, creating a tree like structure. Binary Trees

=Sorting=

There are numerous ways to sort a list of elements. You could sort the list as you add elements to it or sort all of the elements of the list once they've all been added. One method of sorting elements of an array is nicknamed swap sort. The procedure involves looking at each element in the array and comparing it to every element after it and swapping to make the lesser element lower in the array. code format="cpp" int size = 5; int array[] = {5,2,4,15,87}; for(int x = 0; x array[y]){ int tmp = array[y]; array[y] = array[x]; array[x] = tmp; }   } } code This code can be changed to compare floats, strings, or your own structs. It can also be easily changed to support pointers.

=Links=

Programming Techniques