rendered paste body#include <malloc.h>#include <conio.h>#include <io.h>#include <sys\stat.h>#include <stdio.h>#include <stdlib.h>#include <string.h>struct lijst {int getal;struct lijst* volgend;};int geefGetal(struct lijst *hoofd,int i);void sorteerLijst(struct lijst *hoofd);int telAantal(struct lijst *hoofd);struct lijst* sorteerLijsten(struct lijst *hoofd1,struct lijst *hoofd2);void voegToe(struct lijst **hoofd,struct lijst *bron, int j);void voegToeS(struct lijst **hoofd,int j);void printUit(struct lijst *hoofd);void wisselGetallen(struct lijst *hoofd,int i,int j);int main(void){struct lijst *lijst1 = NULL;struct lijst *lijst2 = NULL;voegToeS(&lijst1,5);voegToeS(&lijst1,8);voegToeS(&lijst1,9);voegToeS(&lijst1,2);voegToeS(&lijst1,4);voegToeS(&lijst2,7);voegToeS(&lijst2,1);voegToeS(&lijst2,9);voegToeS(&lijst2,12);voegToeS(&lijst2,13);voegToeS(&lijst2,2);printUit(sorteerLijsten(&lijst1,&lijst2));while(1);}int telAantal(struct lijst *hoofd){ int i = 0; while(hoofd != NULL) { hoofd = hoofd->volgend; i++; } return i;}int geefGetal(struct lijst *hoofd,int i){ int j = 0; while(j < i ) { hoofd = hoofd->volgend; j++; } return hoofd->getal;}void sorteerLijst(struct lijst *hoofd) { int i,j,hulp; int getal1,getal2; int aantal = telAantal(hoofd); struct lijst *nieuw = (struct lijst*) malloc ( sizeof(struct lijst*)* aantal); for (i=0; i < aantal - 1 ;i ++) { for (j= i+1; j < aantal; j++) { getal1 = geefGetal(hoofd,i); getal2 = geefGetal(hoofd,j); if( getal1 > getal2) { wisselGetallen(hoofd,getal1,getal2); } } }}struct lijst* sorteerLijsten(struct lijst *hoofd1,struct lijst *hoofd2){ int i; int nieuwaantal = telAantal(hoofd1)+ telAantal(hoofd2); struct lijst *nieuw = (struct lijst *) malloc ( sizeof(struct lijst*) * nieuwaantal); nieuw->volgend = NULL; for(i = 0; i < telAantal(hoofd1);i++) voegToe(&nieuw,hoofd1,i); for(i = 0; i < telAantal(hoofd2);i++) voegToe(&nieuw,hoofd2,i); sorteerLijst(nieuw); return nieuw; }void voegToe(struct lijst **hoofd, struct lijst *bron,int j) { struct lijst *hulp = *hoofd; struct lijst *nieuw = (struct lijst *) malloc ( sizeof(struct lijst*)); int teller = 0; while(teller < j){ bron = bron->volgend; teller++; } nieuw->getal = bron->getal; nieuw->volgend = NULL; if(hulp == NULL) *hoofd = nieuw; else { while(hulp->volgend != NULL) hulp = hulp->volgend; hulp->volgend = nieuw; }}void voegToeS(struct lijst **hoofd,int j){ struct lijst *hulp = *hoofd; struct lijst *nieuw = (struct lijst *) malloc ( sizeof(struct lijst*)); nieuw->getal = j; nieuw->volgend = NULL; if(hulp == NULL) *hoofd = nieuw; else { while(hulp->volgend != NULL) hulp = hulp->volgend; hulp->volgend = nieuw; }}void printUit(struct lijst *hoofd){ while(hoofd != NULL) { printf("\n%d\t\t%p",hoofd->getal,hoofd->volgend); hoofd = hoofd->volgend; }}void wisselGetallen(struct lijst *hoofd,int i,int j){ int *loci = NULL; int *locj = NULL; int gevonden = 0; while(!gevonden){ gevonden = hoofd->getal == i; if(!gevonden) hoofd = hoofd->volgend; } loci = &hoofd->getal; gevonden = 0; while(!gevonden){ gevonden = hoofd->getal == j; if(!gevonden) hoofd = hoofd->volgend; } locj = &hoofd->getal; *loci = j; *locj = i;}