/* This program sorts an array's values into 
   ascending order */
#include <stdio.h>
#define SIZE 10

int linear_search(int [], int, int);

main() 
{
   int key;
int index; 
   int a[SIZE] = {2, 6, 4, 8, 10, 12, 89, 68, 45, 37};
   int i, pass, hold;
   int j;
   
   printf("Data items in original order\n");
   
   for (i = 0; i <= SIZE - 1; i++)
      printf("%4d", a[i]);

      printf("\n \n");

   for (pass = 1; pass <= SIZE - 1; pass++)  /* passes */

      for (i = 0; i <= SIZE - 2; i++)      /* one pass */
         if (a[i] > a[i + 1]) {      /* one comparison */
            hold = a[i];                   /* one swap */
            a[i] = a[i + 1];
            a[i + 1] = hold;
   for (j = 0; j <= SIZE - 1; j++)
      printf("%4d", a[j]);
      printf(" i=%d pass=%d \n",i,pass);
         }
      printf("\n");

   printf("\nData items in ascending order\n");

   for (i = 0; i <= SIZE - 1; i++)
      printf("%4d", a[i]);

   printf("\n");

   /* Now onto linear search..*/

  printf("type in the keynumber:");
  scanf("%d",&key);

  index = linear_search(a,SIZE,key);
  if (index==(-1)) printf("Sorry, the keyword is not present!\n");
  else 
  printf("The index is :%d\n",index);
  return 0;
}


/*Daniel Peck totally did this... */
/* In the class on Oct. 24, 2006 */

int linear_search(int a[], int size, int key)
{
int i;
for(i= 0; i < size - 1; i++)
  {
if(a[i] == key)
   {
return(i);
   }
  }
return(-1);
}





