noooo
This commit is contained in:
1 parent
045d7367a8
commit
8aa73bde5e
10 files changed
+649
-47
No files matched your search
+109
@@ -0,0 +1,109 @@
|
||||
#include "../common/linkedlist.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> // reimport!!! as
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct CarInfo
|
||||
{
|
||||
int capacity;
|
||||
char *id; // i follow the thing
|
||||
// (0, cap]
|
||||
int reserved;
|
||||
} CarInfo;
|
||||
|
||||
typedef struct Train
|
||||
{
|
||||
dllda Cars;
|
||||
int passengers;
|
||||
} Train;
|
||||
|
||||
// rust is perfect for this let me tell you
|
||||
|
||||
CarInfo *init(int cap, char *id)
|
||||
{
|
||||
CarInfo *c = (CarInfo *)calloc(1, sizeof(CarInfo));
|
||||
if (cap > 0)
|
||||
c->capacity = cap;
|
||||
c->id = strdup(id);
|
||||
return c;
|
||||
}
|
||||
|
||||
int check(CarInfo *c)
|
||||
{
|
||||
if (c->reserved <= 0)
|
||||
return -1;
|
||||
else if (c->reserved > c->capacity)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
int getPassengers(CarInfo *c) { return c->reserved; }
|
||||
int getCapacity(CarInfo *c) { return c->capacity; }
|
||||
|
||||
int printTheCarThing(CarInfo *c)
|
||||
{
|
||||
return printf("CarInfo (id: %s): %d/%d", c->id, c->reserved, c->capacity);
|
||||
}
|
||||
|
||||
void printhere(Train *train)
|
||||
{
|
||||
dllda *new = &train->Cars;
|
||||
int sz = dllda_len(new);
|
||||
printf("size: %d [", sz);
|
||||
uintptr_t *c = (uintptr_t *) calloc(sz, sizeof(uintptr_t));
|
||||
for (int i = sz - dllda_to_list(new, c);
|
||||
printf("(%d: ", i) &&
|
||||
printTheCarThing((CarInfo *)c[i]) &&
|
||||
printf(")") &&
|
||||
(++i < sz); // how to get value
|
||||
printf(", "))
|
||||
;
|
||||
printf("]\n");
|
||||
}
|
||||
|
||||
// HUGE
|
||||
int addPassenger(Train *train, int p)
|
||||
{ // +- supported
|
||||
if (p == 0)
|
||||
return 0; // hey what if we return the excess
|
||||
train->passengers += p;
|
||||
dllda *cars = &train->Cars;
|
||||
int len = dllda_len(cars);
|
||||
// so should this be a fifo or a what
|
||||
int flag = 1;
|
||||
int startPoint = 0, endIncl = len - 1;
|
||||
if (p < 0)
|
||||
{
|
||||
flag = -1;
|
||||
startPoint = endIncl, endIncl = 0;
|
||||
} // its find all over again
|
||||
// so if -4 is smaller than -2 and 4 is smaller than 23
|
||||
for (int i = startPoint; flag * i <= flag * endIncl; i += flag)
|
||||
{ CarInfo *curcar;
|
||||
dllda_query(cars, i, (uintptr_t*) curcar);
|
||||
if (true);
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
|
||||
Train train;
|
||||
train.passengers = 0;
|
||||
dllda *Cars = &train.Cars;
|
||||
Cars = initlda();
|
||||
CarInfo *Car1 = init(55, "gay101");
|
||||
dllda_push(Cars, (uintptr_t)Car1);
|
||||
CarInfo *Car2 = init(73, "top3");
|
||||
dllda_pushleft(Cars, (uintptr_t)Car2);
|
||||
CarInfo *Car3 = init(25, "r1chk1dz");
|
||||
dllda_pushleft(Cars, (uintptr_t)Car3);
|
||||
CarInfo *Car4 = init(14, "prez");
|
||||
dllda_insert(Cars, 2, (uintptr_t)Car4);
|
||||
|
||||
uintptr_t *array = (uintptr_t *)malloc(dllda_len(Cars) * sizeof(CarInfo));
|
||||
dllda_to_list(Cars, array);
|
||||
printhere(&train);
|
||||
return 0;
|
||||
}
|
||||
+52
-16
@@ -1,22 +1,58 @@
|
||||
#include "../common/arraylist.h"
|
||||
// haha i will have to compile manually EVERY TIME HAHAHAHAHAHAHAHA
|
||||
#include <stdio.h>
|
||||
|
||||
ldaArrayList number_to_list(long long int e)
|
||||
{
|
||||
ldaArrayList c;
|
||||
ldalistinit(&c);
|
||||
if (e < 0)
|
||||
{
|
||||
ldalistpush(&c, -1);
|
||||
e = -e;
|
||||
}
|
||||
else
|
||||
ldalistpush(&c, 1);
|
||||
for (; e > 0; e /= 10)
|
||||
ldalistadd(&c, 1, (int) (e % 10));
|
||||
// SHIT IN (array rotato (it means bad))
|
||||
ldalistprint(&c);
|
||||
return c;
|
||||
}
|
||||
|
||||
void displayNumber(ldaArrayList *n)
|
||||
{
|
||||
for (int i = 0, cur; i < ldalistlen(n); i++)
|
||||
{
|
||||
if (ldalistlookup(n, i, &cur) != 0)
|
||||
return;
|
||||
if (cur == -1)
|
||||
printf("-");
|
||||
else
|
||||
printf("%d", cur);
|
||||
}
|
||||
}
|
||||
|
||||
long long int list_to_number(ldaArrayList c)
|
||||
{
|
||||
// SHIT OUT
|
||||
long long ret = 0;
|
||||
int e;
|
||||
for (long long int f = 1; ldalistpop(&c, &e) == 0; f *= 10)
|
||||
{
|
||||
if (e >= 0)
|
||||
ret = ret + e * f;
|
||||
else if (e == -1)
|
||||
ret = -ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
ldaArrayList lda;
|
||||
ldalistinit(&lda);
|
||||
ldalistpush(&lda, 1);
|
||||
ldalistpush(&lda, 2);
|
||||
ldalistpush(&lda, 5);
|
||||
ldalistpush(&lda, 10);
|
||||
ldalistpush(&lda, 20);
|
||||
ldalistpush(&lda, 30);
|
||||
ldalistadd(&lda, 4, 50); // correct af
|
||||
ldalistprint(&lda);
|
||||
int g;
|
||||
ldalistpop(&lda, &g);
|
||||
int f;
|
||||
ldalistremove(&lda, 6, &f);
|
||||
ldalistprint(&lda);
|
||||
printf("%d %d",g, f);
|
||||
ldaArrayList ef = number_to_list(-276482364786342);
|
||||
displayNumber(&ef);
|
||||
printf("\n");
|
||||
printf(" %lld ", list_to_number(ef));
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user