I'm trying to get this linked list project to work, but when I try to run it I get this error:
Lab6 being my project.Lab6 has encountered a problem and needs to close
I don't get any errors while compiling, so I'm unsure what to do.Code:------------------node.h------------------ struct Node { int value; Node *next; }; class linkedList { public: linkedList() {first=0; length=0;} bool operator > (int a); //insert an integer at the end of the linked list using the operator new void displayList(); //display linked list bool Insert(int i, int a); // insert an integer by creating a new node in the location designated by i ~linkedList(); private: Node *first; int length; }; bool linkedList::operator > (int a) { Node *newn, *current; newn = new Node; newn->value = a; newn->next = 0; current = first; while (current->next != 0) current = current->next; current->next = newn; length++; return true; } void linkedList::displayList() { Node *current; current = first; for (int i=0; i<length; i++) { current = current->next; std::cout << current->value; if ((i+1) < length) std::cout << ", "; } } bool linkedList::Insert(int i, int a) { if ((i > (length+1)) || (i < 1)) return false; Node *newn, *current; newn = new Node; newn->value = a; current = first; for (int j=1; j<i; j++) current = current->next; newn->next = current->next; current->next = newn; length++; return true; } linkedList::~linkedList() { Node *current = first; while (current->next != 0) { Node *next = current->next; delete current; current = next; } delete current; } ------------------usingnode.cpp------------------ #include <iostream> #include "node.h" using namespace std; int main() { linkedList L_int; L_int.Insert(1,34); L_int.Insert(1,23); L_int.Insert(3,12); L_int.Insert(2,50); L_int.Insert(1,54); L_int.Insert(7,11); L_int.displayList(); return 0; }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.