CS151 -- Administration
 
 
 
Project 4, due July 17 (Wednesday)
CS151 -- Shawn Stoffer

 
CS151 -- Administration
Project 5, due July 24 (Teusday). Don't sweat it, there will be lots of in class examples... Just pay attention.
CS151 -- Shawn Stoffer


 
 
 
 
 
 
 
 
 

Arrays

Arrays in functions...

void search(int array[], int size, int find)

Just use the []

CS151 -- Shawn Stoffer


 
 
 

Arrays

Arrays in functions...

void search(int array[], int size, int find)
 

CS151 -- Shawn Stoffer


 
 
 
 

Searching

Sequential Search (naive)

Binary Search (really smart...but has constraints)

CS151 -- Shawn Stoffer


 
 
 
 
 
 
 
 
 
 
 

Searching

Sequential Search (naive)
CS151 -- Shawn Stoffer


 
 
 
 

Searching

Sequential Search (naive)

element seqSearch(element array[],
                  int size,
                  element find)
{
  for (int i = 0; i < size; i++) {
    if (array[i] == find) {
      return find;
    }
  }
}

CS151 -- Shawn Stoffer


 
 
 
 
 
 
 
 
 
 
 

Searching

Binary Search
CS151 -- Shawn Stoffer


 
 
 
 
 

Searching

Binary Search
CS151 -- Shawn Stoffer


 
 

Searching

Binary Search
CS151 -- Shawn Stoffer


 
 
 
 
 
 
 
 
 

Searching

Binary Search
CS151 -- Shawn Stoffer


 
 

Searching

Binary Search element search(element array[], int size,
               element find)
{
   int high = size, low = 0;
   int middle = (high+low) / 2;

   while (high > low) {
     if (array[middle] < find) {
       low = middle;
     } else if (array[middle] > find) {
       high = middle;
     } else {
       return element;
     }
     middle = (high+low)/2;
   }
   throw notFound;
}

CS151 -- Shawn Stoffer


 
 
 
 
 
 

Sorting

Sorting -- make a list ordered...
CS151 -- Shawn Stoffer


 
 
 
 
 
 

Sorting

Sorting -- make a list ordered...
CS151 -- Shawn Stoffer


 
 
 
 
 
 
 
 
 

Sorting

Sorting -- make a list ordered...
CS151 -- Shawn Stoffer


 

Sorting

Sorting -- make a list ordered...
CS151 -- Shawn Stoffer


 

Sorting

Sorting -- make a list ordered...
CS151 -- Shawn Stoffer


 
 

Sorting

Sorting -- make a list ordered...
CS151 -- Shawn Stoffer