forked from chemicoholic21/Data-Structures-and-applications
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrays.cpp
More file actions
52 lines (52 loc) · 1.11 KB
/
Copy patharrays.cpp
File metadata and controls
52 lines (52 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<stdio.h>
#include<conio.h>
void selectionSort(int arr[],int n)
{
int i,j,min_pos,temp;
//One by one move boundary of unsorted subarray
for(i=0;i<n-1;i++)
{
min_pos=i;
for(j=i+1;j<n;j++){
if(arr[j]<arr[min_pos])
min_pos=j;
if(min_pos!=i){
temp=arr[i];
arr[i]=arr[min_pos];
arr[min_pos]=temp;
}
}
for(i=0;i<n;i++)
printf("%d",arr[i]);
}
void linearSearch(inr arr[],int n,int x)
{
int i;
for(i=0;i<n;i++)
{
if(x==arr[i])
{
printf("\nposition of element=%d",i+1);
return;
}
}
printf("\nElement %d does not exist in the entered list",x);
}
void main()
{
int arr[30];
int n,i,x;
printf("Enter the number of integers\n");
scanf("%d",&n);
printf("Enter the list\n");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("Enter the number to be found in the list\n");
scanf("%d",&x);
printf("Sorted array:\n");
selectionSort(arr,n);
linearSearch(arr,n,x);
getch();
}