parent
f23eaec9e3
commit
d610ee3a18
@ -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
|
||||
Loading…
Reference in new issue