Structs, Sorting 1, dynamic memory,ETC Flashcards

1
Q

explain how selection sort works.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

explain how the bubble sort works

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain how the insertion sort works

A

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.
`

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

allocation arrows begin

A

inside the box

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

dynamic arrays

A

size determined during the call

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

static arrays

A

Size determine at compile time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Pre conditions

A

if these conditons are met, the function will be executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

post conditions

A

if the pre conditions were met then this is what will happen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

in an assignment statement, *d means

A

in an assignment statement, *d means go to the address stored in d and store the right hand size value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

, how do we free up the memory in the heap that we have grabbed when we did the statement with new in it?

A

delete[]d;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

assuming the user enters the desired size in the variable size.

make a dynamic array called ARR

A

int* ARR

ARR = new int [size]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

reference into the 3d index of a dynamic array using 2 methods.

A

j = d[3]

*(d +3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what does the d mean in *(d +3)

A

the array name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

) How does the text show the current position of the file pointer?

A

we pass the file pointer by reference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly