I need some help on my linked lists app
I'm messing around with linked lists, cause I've just learned (mostly :D ) how to use singly linked lists. I NEED to learn doubly linked ones sometimes soon. Anyway, I decided to go off and experiment, and see if I can do doubly linked lists. Well, I haven't totally implemented the doubly part FULLY yet, but I will. After I solve this. How do I get my p node (i.e. the thingy that traverses the list) to start at the beginning? I use MSVC6 on Win98. Here's the code:
Code:
#include <iostream.h>
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
void New(int v);
class node {
public:
node(node *pre);
int x;
node *next;
node *prev;
private:
};
node::node(node *pre) {
*prev = *pre;
}
void main() {
unsigned long int n[2000];
unsigned int l;
int ch;
n[0] = 0;
n[1] = 1;
l = 2;
clrscr();
cout << "This is a doubly linked list test.\nBy: Scott A. Hand\n";
node *root(NULL);
node *p(NULL);
root->prev = NULL;
do {
clrscr();
cout << flush << "Menu:\n[1] New\n[2] View All\n[3] Quit\n> ";
cin >> ch;
if (ch == 3) {
clrscr();
cout << "This program was made by: Scott A. Hand, goodbye.\nPress any key to quit...\n";
getch();
exit(0);
}
if (ch == 1) {
root->next = new node(root);
cout << "Enter value: ";
cin >> root->x;
root->next = NULL;
}
if (ch == 2) {
p = NULL;
p = root;
do {
cout << p->x << endl;
} while (!p->next == NULL);
getch();
}
} while (ch != 3);
}
Thanks in advance,
Scott