Skip to content

Commit

Permalink
daily upload 12.23
Browse files Browse the repository at this point in the history
  • Loading branch information
TGSpock123 committed Dec 23, 2023
1 parent 4c3665f commit b3e2254
Show file tree
Hide file tree
Showing 42 changed files with 4,091 additions and 200 deletions.
Binary file modified .DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions 10_plus/10.26.c
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;
}
6 changes: 6 additions & 0 deletions 10_plus/10.26_27.h
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);
68 changes: 68 additions & 0 deletions 10_plus/10.27.c
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;
}
59 changes: 59 additions & 0 deletions 10_plus/10.28_yuanDiPaiXu_aiHelp.c
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;
}
2 changes: 1 addition & 1 deletion 10_plus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ project(10_plus C)

set(CMAKE_C_STANDARD 11)

add_executable(10_plus 10.12.c)
add_executable(10_plus 10.28_yuanDiPaiXu_aiHelp.c)
Binary file added 10_plus_2/.DS_Store
Binary file not shown.
Loading

0 comments on commit b3e2254

Please sign in to comment.