checkout is going to KILL ME
losing SO MUCH thank fuck i dont close files
This commit is contained in:
1 parent
efe7783b78
commit
d410e6cd5d
3 files changed
+96
-1
No files matched your search
+3
-1
@@ -68,6 +68,8 @@ int adll_remove(dllda *whatif, nodeld *node)
|
|||||||
// right of left now is null
|
// right of left now is null
|
||||||
if (whatif->end != NULL)
|
if (whatif->end != NULL)
|
||||||
whatif->end->next = NULL;
|
whatif->end->next = NULL;
|
||||||
|
if (whatif->start == whatif->end)
|
||||||
|
whatif->end = NULL; // i do hate life do i
|
||||||
}
|
}
|
||||||
|
|
||||||
whatif->size--;
|
whatif->size--;
|
||||||
@@ -375,7 +377,7 @@ int dllda_from_list(dllda *l, uintptr_t *arr, int size)
|
|||||||
|
|
||||||
// printf("%p %d ", arr[i], *(int *)arr[i]);
|
// printf("%p %d ", arr[i], *(int *)arr[i]);
|
||||||
dllda_push(l, arr[i]);
|
dllda_push(l, arr[i]);
|
||||||
// printf("%d ", *(int*) *t);
|
// printf("%d ", *(int*) *t);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,38 @@
|
|||||||
// feed in a pointer to a function that takes 2 and returns (just like the )
|
// feed in a pointer to a function that takes 2 and returns (just like the )
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
int cmpfunc(const void *a, const void *b)
|
int cmpfunc(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
const int *A = a, *B = b;
|
const int *A = a, *B = b;
|
||||||
return (*A > *B) - (*A < *B);
|
return (*A > *B) - (*A < *B);
|
||||||
}
|
}
|
||||||
|
int _centeredCube(int num) {
|
||||||
|
int low = -num, high = num, mid, result = 0;
|
||||||
|
while (low <= high) {
|
||||||
|
mid = low + (high - low) / 2;
|
||||||
|
|
||||||
|
long long thisSum = (long long) pow(mid, 3) + (long long) pow(mid + 1, 3); // Avoid overflow
|
||||||
|
|
||||||
|
if (thisSum == (long long) num)
|
||||||
|
return mid;
|
||||||
|
else if (thisSum < num) {
|
||||||
|
result = mid; // Store the best approximation so far
|
||||||
|
low = mid + 1;
|
||||||
|
} else {
|
||||||
|
high = mid - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result; // Return the closest guess when exact match is not found
|
||||||
|
};
|
||||||
|
bool centerCube(int num) {
|
||||||
|
int n = _centeredCube(num);
|
||||||
|
long long thisSum = (long long) pow(n, 3) + (long long) pow(n + 1, 3);
|
||||||
|
printf("n = %d, thisSum = %lld, num = %d\n", n, thisSum, num);
|
||||||
|
return thisSum == (long long) num;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char const *argv[])
|
int main(int argc, char const *argv[])
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// Function to perform Cocktail Shaker Sort (Bidirectional Bubble Sort)
|
||||||
|
void cocktailShakerSort(int arr[], int n) {
|
||||||
|
int swapped = 1; // To track if any swaps were made
|
||||||
|
int start = 0; // Starting index
|
||||||
|
int end = n - 1; // Ending index
|
||||||
|
|
||||||
|
while (swapped) {
|
||||||
|
swapped = 0;
|
||||||
|
|
||||||
|
// Forward pass: left to right
|
||||||
|
for (int i = start; i < end; ++i) {
|
||||||
|
if (arr[i] > arr[i + 1]) {
|
||||||
|
// Swap if the current element is greater than the next
|
||||||
|
int temp = arr[i];
|
||||||
|
arr[i] = arr[i + 1];
|
||||||
|
arr[i + 1] = temp;
|
||||||
|
swapped = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no swaps occurred, the array is sorted
|
||||||
|
if (!swapped)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Reduce the end point since the last element is sorted
|
||||||
|
--end;
|
||||||
|
|
||||||
|
// Backward pass: right to left
|
||||||
|
for (int i = end - 1; i >= start; --i) {
|
||||||
|
if (arr[i] > arr[i + 1]) {
|
||||||
|
// Swap if the current element is greater than the next
|
||||||
|
int temp = arr[i];
|
||||||
|
arr[i] = arr[i + 1];
|
||||||
|
arr[i + 1] = temp;
|
||||||
|
swapped = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increment the start point since the first element is sorted
|
||||||
|
++start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to print the array
|
||||||
|
void printArray(int arr[], int n) {
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
printf("%d ", arr[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int arr[] = {5, 1, 4, 2, 8, 0, 3};
|
||||||
|
int n = sizeof(arr) / sizeof(arr[0]);
|
||||||
|
|
||||||
|
printf("Original array: ");
|
||||||
|
printArray(arr, n);
|
||||||
|
|
||||||
|
cocktailShakerSort(arr, n);
|
||||||
|
|
||||||
|
printf("Sorted array: ");
|
||||||
|
printArray(arr, n);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user