1
0

feat: Initial commit

This commit is contained in:
2024-03-22 17:37:24 +01:00
parent 4288bd63a1
commit 6732a7a166
120 changed files with 9620 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
// Laboratorio 8 - Esercizio 2 - ST.c
// Matteo Schiff - s295565
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "ST.h"
#include "Item.h"
struct st {
Item *v;
int N;
int maxN;
};
ST STinit(int N) {
ST st = (ST) malloc(sizeof(*st));
st->v = (Item *) malloc(N * sizeof(Item));
st->N = 0;
st->maxN = N;
return st;
}
void STfree(ST st) {
free(st->v);
free(st);
}
int STinsert(ST st, Item item) {
if (st->N == st->maxN) {
printf("Errore, spazio esaurito nella ST\n");
return -1;
}
st->v[st->N] = item;
st->N++;
return st->N -1;
}
Item STsearchByIndex(ST st, int index) {
if (index >= st->N)
return ITEMnull();
return st->v[index];
}
int STsearch(ST st, Item item) {
int i;
for (i = 0; i < st->N; i++) {
if (strcmp(item.name, st->v[i].name) == 0)
return i;
}
return -1;
}
int STcount(ST st) {
return st->N;
}