This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int get_max(int x, int y) { | |
if (x > y) | |
return x; | |
return y; | |
} | |
int get_sum(int * arr, int arr_size) { | |
int sum = 0, index; | |
for(index = 0; index < arr_size; index++) { | |
sum += index * arr[index]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned pair_in_sorted(int x, int * arr, int arr_size) { | |
int start = 0, end = arr_size - 1; | |
while(start < end) { | |
if (arr[start] + arr[end] == x) | |
return 1; | |
else if (arr[start] + arr[end] < x) | |
start++; | |
else | |
end--; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int get_pivot(int * arr, int arr_size) { | |
int index = 1; | |
while(index < arr_size && arr[index] > arr[index - 1]) { | |
index++; | |
} | |
if (index >= arr_size) | |
return -1; | |
return index; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void rotate_array(int * arr, int arr_size, int rotate_x) { | |
int index, j, temp; | |
for (index = 0; index < rotate_x; index++) { | |
temp = arr[0]; | |
for (j = 1; j < arr_size; j++) { | |
arr[j - 1] = arr[j]; | |
} | |
arr[arr_size - 1] = temp; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
Arr * create_arr(int max_size) { | |
Arr * new_arr = malloc(sizeof(Arr)); | |
new_arr -> size = 0; | |
new_arr -> max_size = 0; | |
new_arr -> items = malloc(max_size * sizeof(int)); | |
if (new_arr -> items != NULL) { | |
new_arr -> max_size = max_size; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void add_sorted(int key, stck * st) { | |
int tmp_arr[100], size = 0, index; | |
while(!is_empty(*st) || get_peek(*st) > key) { | |
tmp_arr[size++] = get_peek(*st); | |
pop(st); | |
} | |
for (index = 0; index < size; index++) { | |
push(tmp_arr[index], st); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned is_same(stck * st1, stck * st2) { | |
while (!is_empty(*st1) && !is_empty(*st2)) { | |
if (get_peek(*st1) != get_peek(*st2)) | |
return 0; | |
pop(st1); | |
pop(st2); | |
} | |
if ((is_empty(*st1) && !is_empty(*st2)) || | |
(!is_empty(*st1) && is_empty(*st2))) | |
return 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void reverse_ll(LinkedList * ll) { | |
Node * curr = ll -> head; | |
while (curr -> next) { | |
insert_first(ll, curr -> next -> key); | |
remove_succesor(curr); | |
} | |
// this for linked list designed with tail pointer: | |
// ll -> tail = curr; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
struct Node { | |
int key; | |
Node * next; | |
}; | |
struct Queue { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
struct Queue { | |
int * keys; | |
int head; | |
int tail; | |
int max_size; | |
}; |