Created
December 4, 2019 23:22
-
-
Save BalintCsala/f11ca5b28c7bc73da100a806f8567ce5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "dicsoseglista.h" | |
#include "debugmalloc.h" | |
Mentes *rendezve_beszur (Mentes *elso, char *nev, int penz, int ido) | |
{ | |
Mentes *uj=(Mentes*)malloc(sizeof(Mentes)); | |
strcpy(uj->nev, nev); | |
uj->penz=penz; | |
uj->ido=ido; | |
uj->kov = NULL; | |
bool beszurva = false; | |
int i = 0; | |
if (elso == NULL) | |
return uj; | |
if (elso->kov != NULL && elso->kov->penz < uj->penz) | |
{ | |
uj->kov = elso; | |
return uj; | |
} | |
else | |
{ | |
for (Mentes *mozgo = elso; mozgo->kov != NULL; mozgo = mozgo->kov) | |
{ | |
if (mozgo->kov->penz < uj->penz) { | |
uj->kov = mozgo->kov; | |
mozgo->kov = uj; | |
beszurva = true; | |
} | |
} | |
} | |
if (!beszurva && i < 5) | |
{ | |
for (Mentes *mozgo = elso; mozgo != NULL; mozgo = mozgo->kov) | |
{ | |
if (mozgo->kov == NULL) | |
{ | |
mozgo->kov = uj; | |
break; | |
} | |
} | |
} | |
else if (!beszurva) | |
{ | |
free(uj); | |
} | |
return elso; | |
} | |
void elment(Mentes *elso) | |
{ | |
FILE *mentes_file = fopen("save.txt", "wt"); | |
int i = 0; | |
for (Mentes *mozgo = elso; mozgo != NULL && i < 5; mozgo = mozgo->kov, i++) | |
{ | |
fprintf(mentes_file, "%s;%d;%d\n", mozgo->nev, mozgo->penz, mozgo->ido); | |
} | |
fclose(mentes_file); | |
} | |
Mentes* betolt() | |
{ | |
FILE *mentes_file = fopen("save.txt", "rt"); | |
if (mentes_file) | |
{ | |
char nev[50]; | |
int penz; | |
int ido; | |
Mentes *elso = NULL; | |
Mentes *mozgo = NULL; | |
while (fscanf(mentes_file, "%[^;];%d;%d\n", nev, &penz, &ido) != EOF) | |
{ | |
Mentes *uj=(Mentes*)malloc(sizeof(Mentes)); | |
strcpy(uj->nev, nev); | |
uj->penz=penz; | |
uj->ido=ido; | |
uj->kov = NULL; | |
if (elso == NULL) | |
{ | |
elso = mozgo = uj; | |
} | |
else | |
{ | |
mozgo->kov = uj; | |
mozgo = uj; | |
} | |
} | |
fclose(mentes_file); | |
return elso; | |
} | |
return NULL; | |
} | |
void mentes_felszabadit(Mentes *elso) | |
{ | |
while (elso != NULL) | |
{ | |
Mentes *kov = elso->kov; | |
free(elso); | |
elso = kov; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment