forked from akij17/Data-Structures-in-Pure-C
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortnsearch.c
More file actions
42 lines (36 loc) · 1.13 KB
/
sortnsearch.c
File metadata and controls
42 lines (36 loc) · 1.13 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
//
// Created by Akshay on 10/29/2018.
//
#include "sortnsearch.h"
#include "arraylist.h"
#include "linkedlist.h"
//Type = 0 for ascending sort Type = 1 for descending sort
void insertionSort_arrayList(arrayList *aList, int type){
int size = aList->size;
int current = 1;
while(current < size){
for(int i = 0; i<current; i++){
if((aList->data)[i]>(aList->data)[current] && type == 0){
int temp = (aList->data)[current];
(aList->data)[current] = (aList->data)[i];
(aList->data)[i] = temp;
}
else if((aList->data)[i]<(aList->data)[current] && type == 1){
int temp = (aList->data)[current];
(aList->data)[current] = (aList->data)[i];
(aList->data)[i] = temp;
}
}
current++;
}
}
int linearSearch_arrayList(arrayList aList, int item){
for(int i = 0; i<aList.size; i++){
if((aList.data)[i] == item){
return i;
}
}
return 0;
}
int linearSearch_linkedList(linkedList lList, int item){
}