okay i got the insert function working, i got the delete function working correctly, but i am having problems with the list function...here is what my program looks like with just dumby variables as the data and not rndm()!!
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, *tmp, *next, *prv, *cur;
nekw = malloc(sizeof(node));
cur = head;
prv = NULL;
nekw->data = insertNum;
if(cur == NULL){
head = nekw;
cur = head;
next = tail;
}//end if statement.
else if(cur->data > nekw->data){
tmp = cur;
cur = nekw;
cur->link = tmp->link;
next = (node*)(cur->link ^ (unsigned long)prv);
if(next == NULL){
next = tmp;
tail = next;
}//end if statement
else{
tmp->link = (unsigned long)cur ^ (unsigned long)next;
cur->link = (unsigned long)prv ^ (unsigned long)tmp;
nekw = (node *)(next->link ^ (unsigned long) cur);
next->link = (unsigned long)nekw ^ (unsigned long)tmp;
cur = tmp;
}//end else statement
}//end else if statement
else{
while((cur != NULL) && (cur->data < nekw->data)){
next = (node *)(cur->link ^ (unsigned long)prv);
prv = cur;
cur = next;
}//end while loop
if(next == NULL){
cur = nekw;
tail = cur;
}//end if statement
else{
nekw->link = (unsigned long) cur ^(unsigned long) next;
cur->link = (unsigned long) nekw ^ (unsigned long) prv;
tmp = (node *)(next->link ^ (unsigned long)cur);
next->link = (unsigned long) nekw ^ (unsigned long) tmp;
cur = nekw;
}//end else
}//end else statement
}//end insert.
void delete(int deleteNum){
node *cur, *prv, *next;
cur = head;
prv = NULL;
while(cur != NULL && (cur->data != deleteNum)){
prv =(node *)(cur->link ^ (unsigned long)next);
prv = cur;
cur = next;
}//end while loop
if(cur != NULL && (cur->data == deleteNum)){
prv->link = (unsigned long) prv ^ (unsigned long) cur;
next->link = (unsigned long) cur^ (unsigned long) next;
free(cur);
}//end if statement.
}//end delete.
void list(){ //int option
int cnt;
node *cur, *prv, *next, *tmp;
tmp = malloc(sizeof(node));
cur = head; //here is where i have a breakpoint for gdb!!!
prv = NULL;
printf("This is the list in acending order: \n");
while(cnt < MAX_NUMBERS){
printf("%d", cur->data);
cnt++;
next = (node *)(cur->link ^ (unsigned long)prv);
prv = cur;
cur = next;
printf(" %d", cur->data);//this is where it will error because cur = NULL
if(cnt % 10 == 0){
printf("\n");
}//end if statement.
}//end while loop
}//end list.
int main(){
head = NULL;
tail = head;
static int cnt, numDelete;
for(cnt=1; cnt < MAX_NUMBERS; cnt++){
insert(cnt);
}//end for loop.
list();
numDelete = 99;
delete(numDelete);
list();
return 0;
}//end main.