I've tried to implement a list within a class. I did this so that I can make 2 or more objects, where each object has a list as it's member. Here is the code to it:(adsbygoogle = window.adsbygoogle || []).push({});

And i accept data by:Code (Text):

struct coeffecient {

int num;

int den;

};

struct polynomial {

float power;

coeffecient coeff;

int polarity;

};

/* Linked List definitions and implementation */

struct Node {

polynomial info;

Node *next;

};

class algebraList {

public:

Node *start, *newptr, *save, *ptr, *rear;

void Insert_End(Node *np) {

if(start == NULL) {

start = rear = np;

} else {

rear->next = np;

rear = np;

}

}

void Display(Node *np) {

while(np != NULL) {

cout<<np->info.power<<" -> ";

np = np->next;

}

cout<<"\n";

}

void additionalNode(polynomial x) {

newptr = createNewNode(x);

if(newptr != NULL) {

cout<<"new node created..."; getch();

} else {

cout<<"error creating node.."; getch(); exit(1);

}

cout<<"inserting node in list..."; getch();

Insert_End(newptr);

}

Node * createNewNode(polynomial n) {

ptr = new Node;

ptr->info = n;

ptr->next = NULL;

return ptr;

}

};

Whenever additionalNode is called, it shows 'Creating new node..', and 'new node created...' messages, as i've written in the additionalNode function [for error checking]. but, after that, when the program tries to run the Insert_End function, the program fives an error, 'The program has encountered a problem and needs to close' and closes.Code (Text):

polynomial x;

cout<<"\n Enter power for the new node: ";

cin>>x.power;

cout<<"creating new node.. "; getch();

listOne.additionalNode(x);

Please help...

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Problems with Linked List and pointers

**Physics Forums | Science Articles, Homework Help, Discussion**