-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c3665f
commit b3e2254
Showing
42 changed files
with
4,091 additions
and
200 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <stdio.h> | ||
#include "10.26_27.h" | ||
int main (void) | ||
{ | ||
int qwer[10] = {4, 2, 6, 3, 1, 9, 5,0,8, 7}; | ||
double tyui[10] = {4.4, 2.2, 6.6, 3.3, 1.1, 9.9, 0.9, 8.8, 7.7}; | ||
|
||
printf ("Max of qwer is %d \n", max (qwer, 10)); | ||
bubble (qwer, 10); | ||
for (int i = 0; i < 10; i ++) | ||
{ | ||
printf ("qwer [%d] = %d \n", i, qwer[i]); | ||
} | ||
printf ("The subscript of max of tyui is %d \n", maxm(tyui, 10)); | ||
printf ("Max of tyui - min of tyui is %f \n", minus(tyui, 10)); | ||
|
||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdio.h> | ||
void sort (int * a, int * b); | ||
void bubble (int ar[], int n); | ||
int max (const int ar [], int n); | ||
double minus (double ar[], int n); | ||
int maxm (const double ar[], int n); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "10.26_27.h" | ||
void sort (int * a, int *b) | ||
{ | ||
int temp; | ||
|
||
temp = *a; | ||
*a = *b; | ||
*b = temp; | ||
} | ||
void bubble (int ar[], int n) | ||
{ | ||
for (int i = 0; i < n - 1; i ++) | ||
{ | ||
for (int j = 0; j < (n - i - 1); j ++) | ||
{ | ||
if (ar[j] > ar[j + 1]) | ||
{ | ||
sort (&ar[j], &ar[j + 1]); | ||
} | ||
} | ||
} | ||
} | ||
int max (const int ar [], int n) | ||
{ | ||
int i = ar[0]; | ||
|
||
for (int q = 0; q < n - 1; q ++) | ||
{ | ||
if (i < ar[q]) | ||
{ | ||
i = ar[q]; | ||
} | ||
} | ||
return i; | ||
} | ||
double minus (double ar[], int n) | ||
{ | ||
double i = ar[0]; | ||
|
||
for (int q = 0; q < n - 1; q ++) | ||
{ | ||
if (i < ar[q]) | ||
{ | ||
i = ar[q]; | ||
} | ||
if (ar[0] > ar[q]) | ||
{ | ||
ar[0] = ar[q]; | ||
} | ||
} | ||
|
||
return (i - ar[0]); | ||
} | ||
int maxm (const double ar[], int n) | ||
{ | ||
int i = 0, p = 0; | ||
|
||
for (double q = ar[0]; i < n - 1; i ++) | ||
{ | ||
if (q < ar[i]) | ||
{ | ||
q = ar[i]; | ||
p = i; | ||
} | ||
} | ||
|
||
return p; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <stdio.h> | ||
|
||
void swap(int* a, int* b) | ||
{ | ||
int temp = *a; | ||
*a = *b; | ||
*b = temp; | ||
} | ||
|
||
int partition(int arr[], int low, int high) | ||
{ | ||
int pivot = arr[high]; | ||
int i = low - 1; | ||
|
||
for (int j = low; j < high; j++) | ||
{ | ||
if (arr[j] <= pivot) | ||
{ | ||
i++; | ||
swap(&arr[i], &arr[j]); | ||
} | ||
} | ||
|
||
swap(&arr[i + 1], &arr[high]); | ||
return i + 1; | ||
} | ||
|
||
void quickSort(int arr[], int low, int high) | ||
{ | ||
if (low < high) | ||
{ | ||
int pi = partition(arr, low, high); | ||
|
||
quickSort(arr, low, pi - 1); | ||
quickSort(arr, pi + 1, high); | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int arr[] = {12, 4, 5, 6, 7, 3, 1, 15}; | ||
int n = sizeof(arr) / sizeof(arr[0]); | ||
|
||
printf("Original array: "); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
printf("%d ", arr[i]); | ||
} | ||
|
||
quickSort(arr, 0, n - 1); | ||
|
||
printf("\nSorted array: "); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
printf("%d ", arr[i]); | ||
} | ||
|
||
return 0; | ||
} |
This file contains 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
Binary file not shown.
Oops, something went wrong.