okay so after a long night and no sleep i figured it all out...but i still have a problem with listing the numbers after i insert it...
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_NUMBERS 100
typedef struct _node{
int data;
unsigned long link;
} node;//end node
node *head, *tail;
void insert(int insertNum){
node *nekw, *next, *prv, *cur;
nekw = malloc(sizeof(node));
cur = head;
prv = NULL;
nekw->data = insertNum;
while((cur != NULL) && (cur->data < nekw->data)){
next = (node *)(cur->link^(unsigned long)prv);
prv = cur;
cur = next;
}//end while loop
if(next == NULL){
next = nekw;
tail = next;
printf("this is the next thing in the list %d\n", tail->data);
}//end if statement
else if(((cur != NULL) && (next != NULL))&& (cur->data > nekw->data)){
nekw->link = (unsigned long) prv ^ (unsigned long)cur;
next = (node *)(cur->link ^ (unsigned long)prv);
cur->link = ((unsigned long)nekw ^ (unsigned long)next);
head = nekw;
}//end else if statement
else{
cur = nekw;
head = cur;
printf("this is head %d\n", head->data);
}//end else statement.
}//end insert.
void list(){
int cnt = 1;
node *cur, *prv, *next;
cur = head;
prv = NULL;
printf("This is the list in ascending order: \n");
printf("%2.1d", cur->data);//this will never print anything!!! even though cur->data = 1!!
while((cur != NULL) && (++cnt < MAX_NUMBERS)){
next = (node *)(cur->link^(unsigned long)prv);//this will always be null
prv = cur, cur = next;
printf("%2.1d", cur->data);//this is where it will error
if(cnt % 10 == 0){
printf("\n");
}//end if statement.
}//end while loop
}//end list.
int main(){
head = NULL;
tail = head;
int cnt;
for(cnt = 1; cnt < MAX_NUMBERS; cnt++){
insert(cnt);
}//end for loop.
list();
return 0;
}//end main.
here is my ouput: it won't go to the next thing in the list...next thing will always be null!!! I checked my insert method over and over again...i found that i never set head the last time...so i made sure that tail and head are set perfect after every case...and still get the error...
Code:
This is the list in ascending order:
Segmentation fault