-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds_functions.c
43 lines (38 loc) · 864 Bytes
/
ds_functions.c
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
#include <stdio.h>
//Function to Print an Array
void printArray(int array[], int size){
int i;
for(i=0;i<size;i++){
printf("%d ", array[i]);
}
}
// Function to Swap 2 value Address
void swap(int *x, int *y){
int temp = *x;
*x = *y;
*y = temp;
}
//Function for Selection Sort Operation
void selectionSort(int array[], int size){
int i, j, minIndex;
for(i=0; i<size-1; i++){
minIndex = i;
for(j=i+1; j<size; j++){
if(array[j] < array[minIndex]){
minIndex = j;
}
}
swap(&array[minIndex], &array[i]);
}
}
// Function for Bubble Sort Operations
void bubbleSort(int a[], int n){
int i, j;
for(i=0; i<n-1; ++i){
for(j=0; j<n-i-1; ++j){
if(a[j]>a[j+1]){
swap(&a[j], &a[j+1]);
}
}
}
}