Professional Documents
Culture Documents
Array Search
o Know the array element we are seeking
(search target).
Linear Search
o Perform search by examining each array
element using a loop and by testing whether
the element matches the target
o Exit search loop when target is found
ddobach
Problem:
Find the index of a number in an
unsorted array of integers
linear_search.c
ddobach
ddobach
ddobach
ddobach
Questions
1. For the search function given earlier:
a) what happens if the last ID stored matches the
target?
b) what happens if several IDs stored match the
target?
ddobach
Problem:
Find the minimum number in an array
of unsorted integers.
find_minimum.c
ddobach
1.
2.
3.
ddobach
ddobach
ddobach
ddobach
Challenge Problem:
Find all occurrences of a number in an
array and replace it with a new value.
search_and_replace.c
ddobach
ddobach
ddobach
Question:
How do you swap 2 numbers?
How many variables do you need?
ddobach
Problem:
Implement the Bubble Sort Algorithm in
an unsorted array of integers.
bubble_sort.c
ddobach
ddobach
ddobach
Syntax:
<datatype> *<name_of_pointer>;
Example:
int *x;
ddobach
int main()
{
int i;
int *p;
i = 5;
p = &i;
return (0);
}
ddobach
ddobach
ddobach