Hey,
So, I've been working on this all day and I'm going crazy as to why my linked list isn't actually linking together. What I mean is that when I print it out, it will only print out the node that was last inserted into the list. I have no idea what's going on. Help me please! Below is a snippet of my code..
Code:
struct Sort_list{
int null_bool; //if 0, then not null; if 1, then null
int val1; //int
struct Sort_list *next;
};
typedef struct Sort_list* sort_list;
sort_list head, tail, curr;
int Insert(sort_list list, void *newObj){
void *p1 = malloc(sizeof(int));
void *p2 = malloc(sizeof(int));
int num;
int value;
int c = 0;
if(list->null_bool == 1){ // if the list is empty
list->val1 = *(int*)newObj;
list->null_bool = 0;
head = list;
}else{ // if the list is not empty
list->val1 = *(int*)newObj;
tail->next = list;
}
tail = list;
tail->next = NULL;
return 0;
}
note: I'm also working with void pointers, but I don't think it's really the issue. So, just ignore those parts..
note:: Tell me if you need more of my code to understand it better.