Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

void* linked list

  • Loading branch information...
commit 776ebb32e02270a97b5088f9283723e51708d818 1 parent c6578c2
Julio Capote authored
BIN  ourlib/a.out
View
Binary file not shown
BIN  ourlib/node
View
Binary file not shown
31 ourlib/node.c
View
@@ -3,13 +3,13 @@
#include "array.c"
struct Node {
- char *data;
+ void *data;
struct Node *next;
struct Node *tail;
int length;
};
-struct Node *new_node(char *val){
+struct Node *new_node(void *val){
struct Node *node = malloc(sizeof(struct Node));
node->next = NULL;
node->data = val;
@@ -22,7 +22,7 @@ int node_length(struct Node *list){
return list->length;
}
-struct Node *node_push(struct Node *list, char *val){
+struct Node *node_push(struct Node *list, void *val){
struct Node *n = new_node(val);
list->tail->next = n;
list->tail = n;
@@ -30,10 +30,10 @@ struct Node *node_push(struct Node *list, char *val){
return n;
}
-char *node_get(struct Node *list, int index){
+void *node_get(struct Node *list, int index){
int starting = 0;
struct Node *n;
- char *result;
+ void *result;
result = list->data;
if(starting == index){
return result;
@@ -53,11 +53,11 @@ char *node_get(struct Node *list, int index){
void print_node(struct Node *list){
struct Node *n;
- printf("%s\n", list->data);
+ printf("%s\n", (char *)list->data);
n = list;
while(n->next != NULL){
n = n->next;
- printf("%s\n", n->data);
+ printf("%s\n", (char *)n->data);
}
}
@@ -79,22 +79,17 @@ void free_node(struct Node *list){
int main(){
- struct Node *node = new_node("asds");
+ struct Node *node = new_node((char *)"asds");
- node_push(node, "foo");
+ node_push(node, (char *)"foo");
- node_push(node, "xxxxx");
+ node_push(node, (char *)"xxxxx");
- // printf("%s\n", node->data);
+ printf("%s", (char *)node_get(node, 1));
- // printf("%s\n", node->next->data);
+ printf("%d", node_length(node));
- // printf("%s\n", node->next->next->data);
-
-// printf("%s", node_get(node, 1));
-
- // printf("%d", node_length(node));
- //print_node(node);
+ print_node(node);
free_node(node);
BIN  ourlib/node.dSYM/Contents/Resources/DWARF/node
View
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.