#include <malloc.h>
#include <stdio.h>
#define N 11
* * Use surveillance whistle to find * *
int search (int array[],int n,int k)
{int i;
i=n-1;
Array[0]=k;
while (array[i]!=k) i--;
return (i);
}
/* Binary Lookup method * *
int halfsearch (int array[],int n,int k)
{int i,j,mid;
I=1;j=n;
while (I<=J)
{mid= (I+J)/2;
if (K==array[mid]) return (mid);
else if (K<array[mid]) j=mid-1;
else i=mid+1;
}
return (0);
}
/* Bubble Sort Method * *
void Mpsort (int array[])
{int i,j,a;
a=0;
for (i=1;i<n;i++)
for (j=i+1;j<n;j++)
if (Array[i]>array[j])
{A=array[i];
ARRAY[I]=ARRAY[J];
Array[j]=a;}
}
/* Direct Insert Sort * *
void Insertsort (int array[])
{int i,j;
for (i=2;i<n;i++)
{Array[0]=array[i];
J=i-1;
while (Array[0]<array[j])
{array[j+1]=array[j--];
ARRAY[J+1]=ARRAY[0];
}
}
}
/* Establish * *
void creat (int array[])
{int i;
printf ("Enter the array:\n");
for (i=1;i<n;i++)
scanf ("%d", &array[i]);
}
/* Display * *
void print (int array[])
{int i;
printf ("The numbers after sort is:\n");
for (i=1;i<n;i++)
printf ("%d", array[i]);
printf ("\ n");
}
Main ()
{int A[11],i,x,chang;
/*printf ("Enter the array\n");
for (i=1;i<11;i++)
scanf ("%d", &a[i]);
* www.bianceng.cn * *
Aga
printf ("\nchang:1: Use watching method finding\n 2:use half method finding\n 3:use directness Intsert method sort\n 4:use Bubble up Method sort\n 5:exit\n ");
scanf ("%d", &chang);
Switch (Chang)
{Case 1:
{creat (a);
printf ("Please int the search number:\n");
scanf ("%d", &x);
printf ("The number station is:%d\n", Search (a,n,x));
Goto Aga;
}
Case 2:
{creat (a);
Insertsort (a);
Print (a);
printf ("Please int the search number:\n");
scanf ("%d", &x);
printf ("The number station is:%d\n", Halfsearch (a,n,x));
Goto Aga;
}
Case 3:
{creat (a);
Insertsort (a);
Print (a);
Goto Aga;
}
Case 4:
{creat (a);
Mpsort (a);
Print (a);
Goto Aga;
}
Case 5:{printf ("exit!\n");
default:{printf ("error!\n"); Goto Aga;
}
}