Basic double linked list added

main
Jonathan Hager 3 years ago
parent f23eaec9e3
commit d610ee3a18
Signed by: JonathanHager
GPG Key ID: 34881E488569708C

@ -1,5 +1,6 @@
{
"files.associations": {
"inputhandling.h": "c"
}
},
"C_Cpp.errorSquiggles": "Disabled"
}

@ -0,0 +1,58 @@
#include "list.h"
#include <stdio.h>
#include <stdlib.h>
Node * ListCreateNode(int *data){
Node *new = (Node *) malloc(sizeof(Node));
new->data = *data;
return new;
}
void ListPrintForward(List *list){
Node *current = list->head;
printf("\n[");
while(current != 0){
printf("%d,", current->data);
current = current->next;
}
printf("]\n");
}
void ListInsertFront(List *list, int data){
Node *new = ListCreateNode(&data);
if(list->head == 0){
list->head = new;
list->tail = new;
}
else if(list->head == list->tail){
list->head = new;
list->head->next = list->tail;
list->tail->prev = list->head;
}
else{
list->head->prev = new;
new->next = list->head;
list->head = new;
}
}
void ListInsertBack(List *list, int data){
Node *new = ListCreateNode(&data);
if(list->head == 0){
list->head = new;
list->tail = new;
}
else if(list->head == list->tail){
list->tail = new;
list->head->next = list->tail;
list->tail->prev = list->head;
}
else{
list->tail->next = new;
new->prev = list->tail;
list->tail = new;
}
}

@ -0,0 +1,29 @@
#ifndef LIST_H_
#define LIST_H_
#include "nodeData.h"
typedef struct Node Node;
typedef struct List List;
typedef struct List {
Node *head;
Node *tail;
} List;
typedef struct Node {
int data;
Node *next;
Node *prev;
} Node;
//Only for internal purpose
Node * ListCreateNode(int *data);
//Print the list in order
void ListPrintForward(List *list);
void ListInsertFront(List *list, int data);
void ListInsertBack(List *list, int data);
#endif

@ -0,0 +1,12 @@
#ifndef NODEDATA_H_
#define NODEDATA_H_
#include "../sprite.h"
typedef union NodeData {
int dataInt;
float dataFloat;
Sprite dataSprite;
} NodeData;
#endif

@ -1,5 +1,5 @@
spiel: main.o sprite.o inputHandler.o
gcc -o spiel main.o sprite.o inputHandler.o -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
spiel: main.o sprite.o inputHandler.o list.o
gcc -o spiel main.o list.o sprite.o inputHandler.o -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
main.o: main.c
gcc -c main.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
@ -10,5 +10,8 @@ sprite.o: sprite.c
inputHandler.o: inputHandler.c
gcc -c inputHandler.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
list.o: List/list.c
gcc -c List/list.c
clean:
rm *.o spiel

@ -3,9 +3,21 @@
#include "sprite.h"
#include "inputHandler.h"
#include "raymath.h"
#include "List/list.h"
int main(){
List testListe;
testListe.head = 0;
testListe.tail = 0;
ListInsertBack(&testListe, 1);
ListInsertBack(&testListe, 2);
ListInsertBack(&testListe, 3);
ListInsertFront(&testListe, 6);
ListInsertBack(&testListe, 4);
ListInsertBack(&testListe, 5);
ListPrintForward(&testListe);
InitWindow(800, 450, "basic window");
Texture2D texture;

Loading…
Cancel
Save