INDEX
[Link] PROGRAMMES PAGE NO REMARKS
1 Program to soart an array ascending order
2 Program to print an array in descending order
3 Program to factorial of given number using
recursion
4 Program to generate Fibonacci series
5 Program to inseart an element in to the all
ready existing array a with a given location
value
6 Program to merging two array
7 Program to input n different values and
traversed by using array
8 Program to search operation
9 Program for deletion operation
10 Program to perform stack operation
11 Program for a queue operation
12 Program for to perform insertion deletion and
display
13 Program for circular queue operation
14 Program for seach an element using LINEAR
SEARCH
15 Program to serch an element using BINARY
SEARCH
16 Program to a list of elements using BUBBLE
SORT
17 Progrom to impliment as ascending
priority queue as a BINARY SEARCH
TREE
18 Program to for a dqueue operation
19 Program to sort an array using selection sort
20 Program to sort a list of element using simple
insertion sort
21 Program to merge 2 sorted list of integers
into single sorted list.
22 Program to sort given number using RADIX
SORT.
23 Program to DOUBLE LINKED LIST.
24 Program to using pointer and dynamic
variable convert BINARY SEARCH.
25 Program to perform insertion, deletion,
display, using circular queue
/*wac prog to soart an array ascending order*/
#include<stdio.h>
#include<conio.h>
main()
{
int limit,i,j,temp;
int a[20];
clrscr();
printf("\n enter the size of the array\n");
scanf("%d",&limit);
printf("\n enter the elemints of the array\n");
for(i=0;i<limit;i++)
scanf("%d",&a[i]);
printf("\n the given array is\n");
for(i=0;i<limit;i++)
printf("\n%d",a[i]);
for(i=0;i<limit;i++)
{
for(j=0;j<limit;j++)
{
if(a[i]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("\n sorted array is\n");
for(i=0;i<limit;i++)
{
printf("\n%d",a[i]);
}
getch();
}
-------------------------output----------------------------------
enter the size of the array
4
enter the elemints of the array
15
10
08
30
the given array is
15
10
08
30
sorted array is
08
10
15
30
/*wac program to sort an array in descending order*/
#include<stdio.h>
#include<conio.h>
main()
{
int a[10],i,j,n,temp=0;
clrscr();
printf("enter the array size");
scanf("%d",&n);
printf("enter any elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("element in descending order\n");
for(i=0;i<n;i++)
{
printf("\n%d",a[i]);
}
getch();
}
----------------------------------output--------------------------------------
enter the array size
4
enter any elements
10
25
68
45
element in descending order
68
45
25
10
/*wac program to factorial of given number*/
#include<stdio.h>
#include<conio.h>
main()
{
int n,f;
clrscr();
printf("enter the number\n");
scanf("%d",&n);
f=fact(n);
printf("factorial of %d\n %d\n",n,f);
getch();
}
int fact(int m)
{
int factor;
if(m==0)
return(1);
else
factor=m*fact(m-1);
return(factor);
}
--------------------------------------output-------------------------------------
enter the number
7
factorial of 7 5040
/*wac program to merging two array*/
#include<stdio.h>
#include<conio.h>
main()
{
int a1[5],a2[5],i1=0,i2=0,i=0,a[10];
clrscr();
printf("enter the value of fist array\n");
i1=0;
while(i1<5)
{
scanf("%d",&a1[i1]);
i1=i1+1;
}
printf("enter the value of second array\n");
i2=0;
while(i2<5)
{
scanf("%d",&a2[i2]);
i2=i2+1;
}
i1=0;
while(i1<5)
{
a[i]=a1[i1];
i=i+1;
i1=i1+1;
}
i2=0;
while(i2<5)
{
a[i]=a2[i2];
i=i+1;
i2=i2+1;
}
i=0;
while(i<10)
{
printf("%d\n",a[i]);
i=i+1;
}
getch();
}
-------------------------------output----------------------------------------
enter the value of fist array
5
2
3
8
7
enter the value of second array
25
40
60
88
45
The merged array’s are
5
2
3
8
7
25
40
60
88
45
/*wac program to generate Fibonacci series*/
#include<stdio.h>
#include<conio.h>
main()
{
int i,fib,n1,n2,n;
clrscr();
printf("how many numbers..........\n");
scanf("%d",&n);
printf("fibonci series\n");
n1=0;
n2=1;
printf("%d\n%d\n",n1,n2);
for(i=3;i<=n;i++)
{
fib=n1+n2;
printf("%d\n",fib);
n1=n2;
n2=fib;
}
getch();
}
------------------------------------------output------------------------------------------
how many numbers..........
10
fibonci series
0
1
1
2
3
5
8
13
21
34
/*wac program to input n different values and traversed by using array*/
#include<stdio.h>
#include<conio.h>
main()
{
int a[5],i,n;
clrscr();
printf("enter the different values",&n);
for(i=0;i<3;i++)
scanf("%d",&a[i]);
printf("the traversed elements of array are");
for(i=0;i<3;i++)
printf("\n%d",a[i]);
getch();
}
--------------------------------------------output---------------------------------------------
enter the different values
786
500
584
the traversed elements of array are
786
500
584
/*wac program for deletion operation*/
#include<stdio.h>
#include<conio.h>
main()
{
int a[10],N,loc,prev,i,num;
clrscr();
printf("enter the length of array\n");
scanf("%d",&N);
printf("enter the array values:\n");
for(i=0;i<N;i++)
{
printf("value %d",i+1);
scanf("%d",&a[i]);
}
printf("enter the location to delete from the array:");
scanf("%d",&loc);
loc=loc-1;
if(loc<N)
{
num=a[loc];
prev=loc;
while(prev<N)
{
a[prev]=a[prev+1];
prev=prev+1;
}
N=N-1;
printf("the resulted o/p is :\n");
for(i=0;i<N;i++)
printf("%d\n",a[i]);
printf("\n the deleted value is %d",num);
}
else
printf("your location is not in the array");
getch();
}
-----------------------------------output----------------------------------------
enter the length of array
enter the array values:
value 1
value 2
50
value 3
80
value 4
40
enter the location to delete from the array:
the resulted o/p is :
50
40
the deleted value is 80
/*wac program to search operation*/
#include<stdio.h>
#include<conio.h>
main()
{
int i,n,found,a[10],key;
clrscr();
printf("enter the limit\n");
scanf("%d",&n);
printf("enter the elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("input array element are_____\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
printf("enter the element to be searched\n");
scanf("%d",&key);
found=0;
for(i=0;i<n;i++)
if(key==a[i])
found=1;
if(found==1)
printf("element found search is succes fully");
else
printf("element not found search is unsuccess fully\n");
getch();
}
-----------------------------------------------output----------------------------------------
enter the limit
5
enter the elements
45
54
65
84
56
input array element are_____
45
54
65
84
56
enter the element to be searched
65
element found search is succes fully
enter the limit
4
enter the elements
80
45
65
22
input array element are_____
80
45
65
22
enter the element to be searched
33
element not found search is unsuccess fully
/*wac program to sort an array using selection sort*/
#include<stdio.h>
#include<conio.h>
main()
{
int a[10],i,n;
clrscr();
printf("enter the number of element\n");
scanf("%d",&n);
printf("enter the elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
selection_sort(a,n);
printf("sorted array is\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
getch();
}
selection_sort(int T[],int max)
{
int i,j,temp;
for(i=0;i<(max-1);i++)
{
for(j=i+1;j<max;j++)
{
if(T[i]>T[j])
{
temp=T[i];
T[i]=T[j];
T[j]=temp;
} } }
return;
}
------------------------------------------output---------------------------------
enter the number of element
3
enter the elements
2
5
1
sorted array is
1
2
5
/*wac program for seach an element using LINEAR SEARCH */
#include<stdio.h>
#include<conio.h>
main()
{
int k,n,item,c[10],loc=0;
clrscr();
printf("\n enter the number of the element:");
scanf("%d",&n);
printf("\n enter the element one by one");
for(k=1;k<=n;k++)
scanf("%d",&c[k]);
printf("\n enter the element to be searched:");
scanf("%d",&item);
c[n+1]=item;
loc=1;
while(c[loc]!=item)
{
loc=loc+1;
}
if(loc==n+1)
printf("\n search is unsuccessful\n");
else
{
printf("\n search is successful\n");
printf("\n the location of the element is %d",loc);
}
getch();
}
-----------------------------------------output--------------------------------------
enter the number of the element:
3
enter the element one by one
10
25
12
enter the element to be searched:
12
search is successful
the location of the element is 3
enter the number of the element:
3
enter the element one by one
10
54
45
enter the element to be searched:
21
search is unsuccessful
/*wac program to inseart an element in to the all ready existing array
a with a given location value*/
#include<stdio.h>
#include<conio.h>
main()
{
int a[5],n,num,loc,prev,i;
clrscr();
printf("enter the size of array\n");
scanf("%d",&n);
printf("enter the array value\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("enter the inserted value\n");
scanf("%d",&num);
printf("enter the location to insert in array\n");
scanf("%d",&loc);
if(loc<=n)
{
prev=n;
while(prev>=loc)
{
a[prev]=a[prev-1];
prev=prev-1;
}
a[prev]=num;
n=n+1;
printf("the resulted output is\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
else
printf("you are location is not in the array\n");
getch();
}
---------------------------------------output---------------------------------------------
enter the size of array
enter the array value
24
12
enter the inserted value
51
enter the location to insert in array
the resulted output is
51
24
12
/*wac program to a list of elements using BUBBLE SORT*/
#include<stdio.h>
#include<conio.h>
main()
{
int n,r,s,temp,c[10];
clrscr();
printf("\n enter the number of elements \n");
scanf("%d",&n);
printf("\n enter the elements one by one \n");
for(r=1;r<=n;r++)
scanf("%d",&c[r]);
{
for(r=1;r<=n;r++)
{
for(s=1;s<=n;s++)
{
if(c[r]<c[s])
{
temp=c[r];
c[r]=c[s];
c[s]=temp;
}
}
}
}
printf("\n the sorted list is as follows \n");
for(r=1;r<=n;r++)
printf("\n %d",c[r]);
getch();
}
---------------------------------output--------------------------------------
enter the number of elements
6
enter the elements one by one
25
45
66
33
85
78
the sorted list is as follows
25
33
45
66
78
85
/*wac program to serch an element using BINARY SEARCH*/
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,n,beg,end,mid,item,loc,temp,c[10];
clrscr();
printf("\n\n enter the limit of elements : \n");
scanf("%d",&n);
printf("\n enter the elements one by one\n");
for(x=1;x<=n;x++)
{
scanf("%d",&c[x]);
}
for(x=1;x<=n-1;x++)
{
for(y=x+1;y<=n;y++)
{
if(c[x]>c[y])
{
temp=c[x];
c[x]=c[y];
c[y]=temp;
}
}
}
printf("\n the sorted list is \n");
for(x=1;x<=n;x++)
printf("%d\n",c[x]);
printf("\n enter the item to be searched:\n");
scanf("%d",&item);
beg=1;
end=n;
mid=(beg+end)/2;
while(beg<=end&&c[mid]!=item)
{
if(item<c[mid])
end=mid-1;
else
beg=mid+1;
mid=(int)(beg+end)/2;
}
if(c[mid]==item)
{
loc=mid;
printf("\n search is successful \n");
printf("\n the location of the element is %d\n",loc);
}
else
{
printf("\n search is unsuccessful \n");
printf("\n item does not found in the list \n");
}
getch();
}
-----------------------------------------output---------------------------------------
enter the limit of elements :
4
enter the elements one by one
21
65
84
78
the sorted list is
21
65
78
84
enter the item to be searched:
2
search is unsuccessful
item does not found in the list
enter the limit of elements :
4
enter the elements one by one
85
45
96
25
the sorted list is
25
45
85
96
enter the item to be searched:
85
search is successful
the location of the element is 3
/*wac program to perform stack operation*/
#include<stdio.h>
#define maxsize 5
int stack[10];
int top=-1,choice;
void main()
{
int rpt=1;
clrscr();
printf("stack operation\n");
while(rpt)
{
printf("----------\n");
printf("1--------->push\n");
printf("2--------->pop\n");
printf("3--------->display\n");
printf("4--------->exit\n");
printf("-----------\n");
scanf("%d",&choice);
switch(choice)
{
case 1:push();
break;
case 2:pop();
break;
case 3:display();
break;
case 4:return;
}
fflush(stdin);
printf("do you want to continue 0 or 1\n");
scanf("%d",&rpt);
}
}
push()
{
int num;
if(top==(maxsize-1))
{
printf("stack is full\n");
return;
}
else
{
printf("enter the element to be pushed \n");
scanf("%d",&num);
top=top+1;
stack[top]=num;
}
return;
}
pop()
{
int num;
if(top==-1)
{
printf("stack is empty \n");
return;
}
else
{
num=stack[top];
printf("poped element is %d\n",stack[top]);
top=top-1;
}
return(num);
}
display()
{
int i;
if(top==-1)
{
printf("stack is empty\n");
return;
}
else
{
printf("the status of the stack is \n");
for(i=top;i>0;i--)
{
printf("%d\n",stack[i]);
}
}
printf("\n");
getch();
}
----------------------------------------output-------------------------------------
stack operation
----------
1--------->push
2--------->pop
3--------->display
4--------->exit
enter your choice
1
enter the element to be pushed
14
do you want to continue 0 or 1
1
----------
1--------->push
2--------->pop
3--------->display
4--------->exit
enter your choice
3--------->display
4--------->exit
enter your choice
2
poped element is 14
do you want to continue 0 or 1
1
----------
1--------->push
2--------->pop
3--------->display
4--------->exit
enter your choice
3
stack is empty
do you want to continue 0 or 1
1
----------
1--------->push
2--------->pop
3--------->display
4--------->exit
enter your choice
4
/*w a c program for a queue operation */
#include<stdio.h>
#include<conio.h>
#define maxsize 10
int queue[10],front=0,rear=-1;
main()
{
int choice=0;
clrscr();
while(choice !=4)
{
printf("1. insert\n");
printf("2. delete\n");
printf("3. display\n");
printf("4. exit\n");
printf("enter the choice: \n");
scanf("%d",&choice);
switch(choice)
{
case 1:insert();
break;
case 2:delete();
break;
case 3:display();
break;
case 4:choice=4;
break;
}
}
}
insert()
{
int element;
printf("enter the element to be queued\n");
scanf("%d",&element);
if(!qfull())
{
rear=rear+1;
queue[rear]=element;
printf("data has been pushed \n");
}
}
delete()
{
int data;
if(!qempty())
{
data=queue[front];
front=front+1;
printf("data is deleted is%d\n",data);
}
else
printf("deleted\n");
}
display()
{
int i;
printf("element is queue are \n");
for(i=front;i<=rear;i++)
printf("%d",queue[i]);
}
qfull()
{
if(rear>=(maxsize-1))
{
printf("queue is full \n");
return(1);
}
else
return(0);
}
qempty()
{
if(front>rear)
{
printf("queue is empty\n");
return(1);
}
else
return(0);
}
--------------------------------------------output-------------------------------------------------
1. insert
2. delete
3. display
4. exit
enter the choice:
1
enter the element to be queued
4
data has been pushed
1. insert
2. delete
3. display
4. exit
enter the choice:
3
element is queue are
41. insert
2. delete
[Link]
[Link]
enter the choice:
2
data is deleted is4
1. insert
2. delete
3. display
4. exit
enter the choice:
4
/*WAC program to perform insertion, deletion and display using
single linked list*/
#include<stdio.h>
#include<alloc.h>
#include<stdlib.h>
typedef struct node
{
int job_id;
char name[20],job_des[20];
struct node*next;
}node;
node*first=NULL;
main()
{
void insert(int jid,char name [],char job_des[]);
void display();
void delete(int jid);
void search(int jid);
int ch,jid;
char name[20],jdes[20];
clrscr();
do
{
printf("\nenter 1->linsert\n");
printf("\n2->ldelete\n3->lsearch\n->display\n5->exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("enter the job id \n");
scanf("%d",&jid);
printf("enter the job name \n");
scanf("%s",name);
printf("enter the job designation \n");
scanf("%s",jdes);
insert(jid,name,jdes);
break;
case 2:
printf("enter the job_id to be deleted\n");
scanf("%d",jid);
delete(jid);
break;
case 3:
printf("enter the job_id to be searched \n");
scanf("%d",&jid);
search(jid);
break;
case 4:
printf("contents of the list\n");
display();
getch();
break;
}
}
while(ch!=5);
getch();
}
void insert(int jid,char name[20],char job_des[20])
{
node*nn;
nn=(node*)malloc(sizeof(node));
if(nn==NULL)
{
printf("insufficient memory\n");
getch();
return;
}
nn->job_id=jid;
strcpy(nn->name,name);
strcpy(nn->job_des,job_des);
nn->next=first;
first=nn;
}
void delete(int jid)
{
node*temp,*prev;
if(first==NULL)
{
printf("empty list \n");
getch();
return;
}
temp=first;
if(first->job_id==jid)
{
first=first->next;
free(temp);
return;
}
temp=first->next;
prev=first;
/* searching the job id */
while(temp->job_id==jid && temp!=NULL)
{
prev=prev->next;
temp=temp->next;
}
if(temp==NULL)
{
printf("\n job_id not found \n");
getch();
return;
}
/* delete the node is job id is found */
free(temp);
prev->next=temp->next;
}
void display()
{
node*temp;
temp=first;
while(temp!=NULL)
{
printf("%d %s %s\n", temp->job_id,temp->name,temp->job_des);
temp=temp->next;
}
printf("null");
}
void search(int jid)
{
node*temp;
temp=first;
while(temp!=NULL)
{
if(temp->job_id==jid)
{
printf("job id in the persent in the list \n");
getch();
return;
}
temp=temp->next;
}
printf("job id not persent in the list \n");
getch();
}
----------------------------------output---------------------------------------
enter 1->linsert
2->ldelete
3->lsearch
->display
5->exit
1
enter the job id
102
enter the job name
kas
enter the job designation
a
enter
1->linsert
2->ldelete
3->lsearch
->display
5->exit
4
contents of the list
102 kas a
null
enter 1->linsert
2->ldelete
3->lsearch
->display
5->exit
5
/* w ac program for circular queue operation*/
#include<stdio.h>
char queue[20][15];
int front=0,rear=0,n=5;
main()
{
int choice=0;
clrscr();
while(choice!=4)
{
printf("1. cqinsert\n"); printf("2. cqdelet\n"); printf("3. cqdisplay\n"); printf("4. exit\n");
printf("enter the your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:cqinsert();
break;
case 2:cqdelet();
break;
case 3:cqdisplay();
break;
case 4:choice=4;
break;
} } }
cqinsert()
{
rear=(rear+1)%n;
if(front==rear)
printf("queue is full\n");
else
{
printf("ntrer the element to be queue\n");
scanf("%s",queue[rear]);
}
}
cqdelete()
{
if(front==rear)
printf("queue is empty\n");
else{
front=(front+1)%n;
printf("deleted element is %s\n",queue[front]);
}
getch();
}
cddisplay()
{
int i;
if(front==rear)
printf("queue is empty \n");
else
{
printf("the status of is");
for(i=front;i<=rear;i++)
printf("%s\n",queue[i]);
}
if(front>rear)
{
for(i=front;i<n;i++)
printf("%s",queue[i]);
for(i=0;i<=rear;i++)
printf("%s",queue[i]);
}
getch();
}
----------------------------------output---------------------------------------
1. cqinsert
2. cqdelete
3. cqdisplay
4. exit
enter the your choice
1
ntrer the element to be queue
6
1. cqinsert
2. cqdelete
3. cqdisplay
4. exit
enter the your choice
3
the status of is
6
1. cqinsert
2. cqdelete
3. cqdisplay
4. exit
enter the your choice
2
deleted element is 6
1. cqinsert
2. cqdelete
3. cqdisplay
4. exit
enter the your choice
3
queue is empty
/*w a c program to sort a list of element using simple insertion sort*/
#include<stdio.h>
#include<conio.h>
main()
{
int a[10],i,n,t[10];
clrscr();
printf("enter the number of elements\n");
scanf("%d",&n);
printf("enter the elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
insertion_sort(a,n); /*function call*/
return;
}
/*funcation to simple insertion sort*/
insertion_sort(int t[],int max)
{
int i,j,item;
for(i=1;i<max;i++)
{
item=t[i];
for(j=i-1;item<t[j]&&j>=0;j--)
{
t[j+1]=t[j];
}
t[j+1]=item;
}
printf("sorted array is......\n");
for(i=1;i<max;i++)
printf("%d\n",t[i]);
return;
}
--------------------------------------output-------------------------------------------------
Enter the number of elements
5
Enter the elements
40
30
50
60
10
Sorted array is-------------
10
30
40
50
60
/*wac program to for a dqueue operation*/
#include<stdio.h>
#include<conio.h>
#define QUEUE_SIZE 5
typedef struct
{
int q[QUEUE_SIZE];
int front;
int rear ;
}
queue;
void insert_front(int item,QUEUE*a)
{
if(a->front==0&&a->rear==-1)
a->q[++(a->rear)]=item;
else if(a->front!=0)
a->q[--(a->front)]=item;
else
printf("front insertion not possible\n");
}
void insert_rear(int item,queue*a)
{
if(a->rear==QUEUE_SIZE-1)
{
printf("rear insertion not possible\n");
return;
}
a->q[++(a->rear)]=item;
}
void delete_front(queue*a)
{ if(a->front>a->rear)
{
printf("queue is empty\n");
return;
}
printf("the elements deleted is%d\n",a->q[a->front++]);
if(a->front>a->rear)
{
a->front=0;
a->rear=-1;
}
}
void delete_rear(QUEUE*a)
{
if(a->front>a->rear)
{
printf("queue is empty\n");
return;
}
printf("the element deleted is %d\n",a->q[a->rear--]);
if(a->front>a->rear)
{
a->front=0;
a->rear=-1;
}
}
void display(QUEUE*a)
{
int i;
if(a->front>a->rear)
{
printf("queue is empty\n");
return;
}
printf("the contents of queued\n");
for(i=a->front;i<a->rear;i++)
printf("%d\n",a->q[i]);
}
void main()
{
QUEUE a;
int item,choice;
clrscr();
[Link]=0;
[Link]=-1;
for(;;)
{
printf("1------------: insert_front\n");
printf("2------------: insert_rear\n");
printf("3------------: delete_front\n");
printf("4------------: delete_rear\n");
printf("5------------: display\n");
printf("6------------: exit\n");
printf("enter the choice :\n");
scanf("%d",%choice);
switch(choice)
{
case 1:
printf("enter the item to be inserted:\n");
scanf("%d",&item);
insert_front(item,&a);
break;
case 2:
printf("enter the item to be inserted\n");
scanf("%d",&iten);
break;
case 3:
delete front (&a);
break;
case 4:
delete rear (&a);
break;
case 5:
display(&a);
break;
default:
exit(0);
}
}
getch();
------------------------------------output--------------------------------------------------
[Link] node at beginning.
[Link] before given node
[Link] a given node
[Link]
[Link]
Enter your choice
1
Add node at begning
1 location
Node added at the begning succcesfuly
Enter your choice
2
Insert befor e given node
19
Node inserted before given node
Enter your choice
3
Enter given number :
10
10 th given node deleted
Enter your choice
4
NULL>20>NULL
Enter your choice
5
exit
/*w a c progrom to impliment as ascending priority queue as a
BINARY SEARCH TREE*/
#include<stdio.h>
#include<conio.h>
struct tree
{
int info;
struct tree*left,*right;
};
typedef struct tree nod;
nod*root;
void inorder (nod*),insert (nod**,int),search(int,nod*),binary();
void main ()
{
clrscr();
binary();
getch();
}
void binary ()
{
int item,ch;
printf("enter the element one by one &enter 0 to stop:\n");
scanf("%d",&item);
root=0;
while(item!=0)
{
insert (&root,item);
scanf("%d",&item);
}
printf("\t\t the sorted list\n");
printf("\t\t item \t\t pointer\n");
inorder(root);
printf("\n\t enter the item to be search:");
scanf("item",root);
search(item,root);
}
void insert (nod**ptr,int item)
{
if((*ptr)==0)
{
(*ptr)=(nod*)malloc(size of(nod));
(*ptr)->info=item;
(*ptr->left=(*ptr)->right=0;
}
else
if(item<(*ptr)->info)
insert(&((*ptr)->left),item);
else
insert(&((*ptr)->right),item);
}
void inorder (nod*ptr)
{
if(ptr!=0)
{
inorder(ptr->left);
printf("\n\t%d\t\t%u",ptr->info,ptr);
inorder (ptr->right);
}
}
void search(int item,nod*ptr)
{
while ((ptr->info!=item)&&(ptr!=0))
{
if(ptr->info>item)
ptr=ptr->left;
else
ptr=ptr->right;
}
if(ptr==0)
printf("\t\t search is unsuccessfully\n");
else
printf("\t\t search item and its pointer is %d %d",item,ptr);
}
----------------------------------------------output-----------------------------------------------------
enter the element one by one &enter 0 to stop:
9
7
5
4
3
0
The sorted list
Item pointer
3 3272
4 3256
5 3240
7 3224
9 3208
Enter the item to be search : 5
Search is successfully
Search item and its pointer is 5 3240