Structs, Sorting 1, dynamic memory,ETC Flashcards
explain how selection sort works.
The function begins with the first of the 2 counters on the final item in the array. (length-1)
a second counter then finds the largest item in the array from 0-length-1.
the program swaps the largest with the last.
the new limit of searching becomes length -2.
the largest from 0-length -2 is now swapped with new end.
this continues until the array is sorted.
explain how the bubble sort works
the bubble sort makes passes from left to right on the array.
it compairs the first 2 values, if they are in order than no switch is done. else they are swapped.
after this both counters iterate.
this function does this until the array is sorted
takes as much as n-1 passes
Explain how the insertion sort works
divide the array into 2 sections sorted and unsorted.
sorted contains only the first value. The second value is then coppied to a temp. if it is less than the value before. that value moves to where temp was. If the value before it was swapped then it continues. sorted increases by 1.
`
allocation arrows begin
inside the box
dynamic arrays
size determined during the call
static arrays
Size determine at compile time
Pre conditions
if these conditons are met, the function will be executed.
post conditions
if the pre conditions were met then this is what will happen
in an assignment statement, *d means
in an assignment statement, *d means go to the address stored in d and store the right hand size value
, how do we free up the memory in the heap that we have grabbed when we did the statement with new in it?
delete[]d;
assuming the user enters the desired size in the variable size.
make a dynamic array called ARR
int* ARR
ARR = new int [size]
reference into the 3d index of a dynamic array using 2 methods.
j = d[3]
*(d +3)
what does the d mean in *(d +3)
the array name
) How does the text show the current position of the file pointer?
we pass the file pointer by reference