Page 2 of 2

Posted: Fri Aug 24, 2007 2:45 pm
by Zacariaz
ok, i though i had it all figured out, to me this should work without problems, but maybe youre all of another oppinion cause theres definently some trouble somewhere allthough its kinda hard to pinpoint...

Code: Select all

#include <iostream>
class T {
    struct node { // well this is obious
      unsigned long ID; // uniquesnode id
      node *next;
      node *prew;
    };
    node *root;
    unsigned long ncount; // number of nodes
  public:
    T(unsigned long i) { // initializing and constructing
      unsigned long id = 0;
      ncount = i;
      root = new node;
      node *temp = root;
      for(int n = 1; n < ncount; n++, id++) {
        temp->ID = id;
        temp->next = new node;
        temp->next->prew = temp;
        temp = temp->next;
      }
      temp->next = root; // making it circular, well i though it would
      root->prew = temp;
    }
    void Print_List() { // a little print func that should print the whole list
      while(root->ID < root->next->ID) {
        std::cout << root->ID << std::endl;
        root = root->next;
      }
    }
};

Posted: Fri Aug 24, 2007 2:54 pm
by Zacariaz
problem solved so never mind.
comments ofcourse still welcome.

Code: Select all

#include <iostream>
class T {
    struct node {
      unsigned long ID;
      node *next;
      node *prew;
    } *root;
  public:
    T(unsigned long i) {
      root = new node;
      node *temp = root;
      temp->ID = 0;
      for(unsigned long n = 1; n < i; n++) {
        temp->next = new node;
        temp->next->prew = temp;
        temp = temp->next;
        temp->ID = n;
      }
      temp->next = root;
      root->prew = temp;
    }
    void Print_List() {
      do {
        std::cout << root->ID << std::endl;
        root = root->next;
      } while(root->ID != 0);
    }
};