Return to Jeff's Main Page

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
My Intro to Object-Oriented Programming  
 
 
 
Class Notes

Wednesday November 15 , 2000
 
At the beginning of class,  CG continued discussion about Programming Assignment # 05 and the specifications of the Word Class and Dictionary Class for that assignment. 

CG then showed us some basic search and sort programs. 


Write a method to search an array of integers for a given integer.    Unlike the search methods of our Dictionary Class,  this will be a static method. 

static private boolean search (int x,  int a [])
{

for (int i = 0;    i < a.length;    i + +)
{
if (a [i]    ==    x)
{
return true;
}
return false;

Here is a program which will sort an array of integers from smallest value to highest value: 

for (int i = 0;    i < a.length;    i + +)
{

for (int s = i + 1;    s <    a.length;    s + +)
{
if (a [i] > a [s])
{
int temp = a [i];
a [i] = a [s];
a [s] = temp;
}
}
}