local node2 = graphs.add_node(graph)
local node3 = graphs.add_node(graph)
+ print("NODES", node1, node2, node3)
+
graphs.add_directed(graph, node1, node2, 2)
graphs.add_directed(graph, node2, node3, 4)
+
+ graphs.print_graph(graph)
end
function love.update()
#ifndef __GRAPH_ALGORITHM_H__
#define __GRAPH_ALGORITHM_H__
+
+
#endif
\ No newline at end of file
}
return 0;
-
}
static connect find_node(header head, int node_id)
int get_nodes(lua_State *L)
{
header head = (header) lua_touserdata(L, 1);
- lua_pop(L, 1);
+ lua_pop(L, 1); // Take off the pointer parameter
- lua_newtable(L);
+ lua_newtable(L); // Push a new table onto the stack
int index = 1;
for (connect jogger = head->front; jogger != NULL; jogger = jogger->next_node) {
- lua_pushnumber(L, index);
- lua_newtable(L);
+ lua_pushnumber(L, index); // Push the next index of the node, sets up for settable call
+ lua_newtable(L); // Push on the table that will store each node
+
+ // Add the fields to our node table
lua_pushnumber(L, jogger->node_id);
lua_setfield(L, 3, "id");
lua_pushnumber(L, jogger->y);
lua_setfield(L, 3, "y");
+ // Put our node table in the table we are returning
lua_settable(L, 1);
index++;
return 1;
}
-
int print_graph(lua_State *L)
{
header head = (header)lua_touserdata(L,1);
#include "utils.h"
-int top(sq_node_p stack_top)
+int sq_top(sq_node_p stack_top)
{
if(stack_top == NULL)
{
return stack_top->value;
}
-int front(sq_node_p queue_front)
+int sq_front(sq_node_p queue_front)
{
if(queue_front == NULL)
{
}
//FUNCTIONS HANDELING CHANGING THE STACK
-sq_node_p push(sq_node_p stack_top, int val)
+sq_node_p sq_push(sq_node_p stack_top, int val)
{
sq_node_p new_node = (sq_node_p)malloc(sizeof(sq_node));
new_node->value = val;
return new_node;
}
-sq_node_p pop(sq_node_p stack_top)
+sq_node_p sq_pop(sq_node_p stack_top)
{
sq_node_p temp = stack_top;
}
//FUNCTIONS HANDELING CHANGING THE QUEUE
-sq_node_p enque(sq_node_p front_of_queue, int val)
+sq_node_p sq_enque(sq_node_p front_of_queue, int val)
{
sq_node_p new_node = (sq_node_p)malloc(sizeof(sq_node));
new_node->value = val;
return front_of_queue;
}
-sq_node_p deque(sq_node_p front_of_queue)
+sq_node_p sq_deque(sq_node_p front_of_queue)
{
if(front_of_queue == NULL)
{
return front_of_queue;
}
-void print_sq(sq_node_p sq)
+void sq_print(sq_node_p sq)
{
sq_node_p runner = sq;
struct sq_node * next;
} sq_node, *sq_node_p;
+int sq_top(sq_node_p stack_top);
+int sq_front(sq_node_p queue_front);
+
+sq_node_p sq_push(sq_node_p stack_top, int val);
+sq_node_p sq_pop(sq_node_p stack_top);
+sq_node_p sq_enque(sq_node_p front_of_queue, int val);
+sq_node_p sq_deque(sq_node_p front_of_queue);
+
+void sq_print(sq_node_p sq);
+
+// Helper macros that make the call site of these functions cleaner
+#define push(sq, val) ((sq) = sq_push( (sq), (val)))
+#define pop(sq, val) ((sq) = sq_pop( (sq), (val)))
+#define enque(sq, val) ((sq) = sq_enque((sq), (val)))
+#define deque(sq, val) ((sq) = sq_deque((sq), (val)))
#endif
\ No newline at end of file