ok, i know for a fact that the display function works correctly. and i know the coding for the actual adding of the linked lists also works, but it only works when i keep it in main. i just tried to add it to another function (the adding part) and it keeps erroring out as soon as i try to display. like i said, if i keep the code for adding the linked list in main, everything works perfectly. so i know its a problem with the code to add. i heard you're suppose to use pointers to pointers, but im not sure how or why you use them.Code:#include <iostream> #include <stdlib.h> #include <conio.h> #define NEXT 50 #define PREV 49 using namespace std; typedef struct node { int a; node *next; node *prev; }NODE; //Function prototypes void display(node *head); void addnode(node *current, node *head); int main() { NODE *current = NULL; NODE *head = NULL; for (int i = 0; i < 1; i++) addnode(current,head); display (head); system("PAUSE"); return 0; } void addnode(node *current, node *head) { node *newnode = new node; cout << "input a value: "; cin >> newnode->a; if (head == NULL) { head = newnode; current = newnode; current->next = NULL; current->prev = NULL; }// if statement else { newnode->prev = current; current->next = newnode; current = newnode; current->next = NULL; }// else statement } void display(node *head) { int ch; node *show = head; cout << show->a << endl; while(1) { ch =getch(); if (ch == PREV) { if (show->prev != NULL) { show = show->prev; cout << show->a << endl; } } if (ch == NEXT) { if (show->next != NULL) { show = show->next; cout << show->a << endl; } } } }
please advise
thanks



LinkBack URL
About LinkBacks




