Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

2
Task/Arrays/C/arrays-1.c Normal file
View file

@ -0,0 +1,2 @@
int myArray2[10] = { 1, 2, 0 }; /* the rest of elements get the value 0 */
float myFloats[] ={1.2, 2.5, 3.333, 4.92, 11.2, 22.0 }; /* automatically sizes */

59
Task/Arrays/C/arrays-10.c Normal file
View file

@ -0,0 +1,59 @@
#include <stdlib.h>
#include <stdio.h>
typedef struct node{
char value;
struct node* next;
} node;
typedef struct charList{
node* first;
int size;
} charList;
charList createList(){
charList foo = {.first = NULL, .size = 0};
return foo;
}
int addEl(charList* list, char c){
if(list != NULL){
node* foo = (node*)malloc(sizeof(node));
if(foo == NULL) return -1;
foo->value = c; foo->next = NULL;
if(list->first == NULL){
list->first = foo;
}else{
node* it= list->first;
while(it->next != NULL)it = it->next;
it->next = foo;
}
list->size = list->size+1;
return 0;
}else return -1;
}
int removeEl(charList* list, int index){
if(list != NULL && list->size > index){
node* it = list->first;
for(int i = 0; i < index-1; i++) it = it->next;
node* el = it->next;
it->next = el->next;
free(el);
list->size--;
return 0;
}else return -1;
}
char getEl(charList* list, int index){
if(list != NULL && list->size > index){
node* it = list->first;
for(int i = 0; i < index; i++) it = it->next;
return it->value;
}else return '\0';
}
static void cleanHelp(node* el){
if(el != NULL){
if(el->next != NULL) cleanHelp(el->next);
free(el);
}
}
void clean(charList* list){
cleanHelp(list->first);
list->size = 0;
}

1
Task/Arrays/C/arrays-2.c Normal file
View file

@ -0,0 +1 @@
#define MYFLOAT_SIZE (sizeof(myFloats)/sizeof(myFloats[0]))

5
Task/Arrays/C/arrays-3.c Normal file
View file

@ -0,0 +1,5 @@
long a2D_Array[3][5]; /* 3 rows, 5 columns. */
float my2Dfloats[][3] = {
1.0, 2.0, 0.0,
5.0, 1.0, 3.0 };
#define FLOAT_ROWS (sizeof(my2Dfloats)/sizeof(my2dFloats[0]))

11
Task/Arrays/C/arrays-4.c Normal file
View file

@ -0,0 +1,11 @@
int numElements = 10;
int *myArray = malloc(sizeof(int) * numElements); /* array of 10 integers */
if ( myArray != NULL ) /* check to ensure allocation succeeded. */
{
/* allocation succeeded */
/* at the end, we need to free the allocated memory */
free(myArray);
}
/* calloc() additionally pre-initializes to all zeros */
short *myShorts = calloc( numElements, sizeof(short)); /* array of 10 */
if (myShorts != NULL)....

2
Task/Arrays/C/arrays-5.c Normal file
View file

@ -0,0 +1,2 @@
myArray[0] = 1;
myArray[1] = 3;

1
Task/Arrays/C/arrays-6.c Normal file
View file

@ -0,0 +1 @@
printf("%d\n", myArray[1]);

3
Task/Arrays/C/arrays-7.c Normal file
View file

@ -0,0 +1,3 @@
*(array + index) = 1;
printf("%d\n", *(array + index));
3[array] = 5;

10
Task/Arrays/C/arrays-8.c Normal file
View file

@ -0,0 +1,10 @@
#define XSIZE 20
double *kernel = malloc(sizeof(double)*2*XSIZE+1);
if (kernel) {
kernel += XSIZE;
for (ix=-XSIZE; ix<=XSIZE; ix++) {
kernel[ix] = f(ix);
....
free(kernel-XSIZE);
}
}

3
Task/Arrays/C/arrays-9.c Normal file
View file

@ -0,0 +1,3 @@
int *array = malloc (sizeof(int) * 20);
....
array = realloc(array, sizeof(int) * 40);