Search (Article Or Program)

09 June 2011

menue program of array with (using) Pointers 1. insert 2. delete 3. searchin 4. replace

/*menue program of array 1. insert 2. delete 3. searchin 4. replace*/
#include
#include
#include
#include
void display(int);
void insert(int*);
void traverse(int*);
void deletion(int*,int);
void sort(int*);
void search(int*,int);
static int n;
int main()
{
clrscr();
int choice=10,pos,ele;
int*x;
printf("\n\n\n\n\n\nEnter Number of elements in array;");
scanf("%d",&n);
x=(int*)malloc(n*sizeof(int));
while(choice!=0)
{
printf("\n\n\n\n\n\n\n\n\nOperation MENUE\n\n\n\n\n\n\n");

printf("1.Insert an integer\n");
printf("2.Traverse the ADT-Array\n");
printf("3.Delete an Element\n");
printf("4.Sort the Array\n");
printf("5.Search an Interger\n");
printf("6.Exit the Program\n");
printf("Insert Your Choice Number\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
insert(x);
getch();
break;
case 2:
traverse(x);
getch();
break;
case 3:
printf("\n\n\n\n\n\n\n Please enter the postion of element to be deleted;\n");
scanf("%d",&pos);
deletion(x,pos);
traverse(x);
getch();
break;
case 4:
sort(x);
traverse(x);
getch();
break;
case 5:
printf("\n\n\n\nPlease Enter The Element to be Searched\n:");
scanf("%d",&ele);
search(x,ele);
getch();
break;
case 6:
exit(0);
getch();
break;
}
}
return 0;
}
/*insert in array*/
void insert(int*p)
{
int i=0,val;
while(i!=n)
{
printf("\n\n\n\n\nInser the value to be Inserted\n");
scanf("%d",&val);
p[i]=val;
i++;
}
}
/*****traversal*********/
void traverse(int*p)
{
int i=0;
while(i!=n)
{
printf("\n\n\n\n\n\n %d\n",p[i]);
i++;
}
}
/*deletion*/
void deletion(int*p,int a)
{
int i=a;
printf("\n\n\n\n\nthe number deleted is : %d",p[i-1]);
i=a-1;
while(ip[j])
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
}
}
/*search*/
void search(int*p,int a)
{
int i=0;
int flag=0;
while(i<=n)
{
if(p[i]==a)
{
flag=1;
printf("\the element found at position %d",i+1);
break;
}
i++;
}
if(flag==0)
printf("\n\n\n\n\n\n\nsearch ended unsuccessfully. elelment NOt found!!!;-(");
}