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 - The Fusion of Science and Community**

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

# Problems with Linked List and pointers

Loading...

Similar Threads - Problems Linked List | Date |
---|---|

Fortran for Computational Fluid Dynamics Problems | Jan 11, 2018 |

Hacking: Legal and Ethical Problems | Dec 6, 2017 |

Silver Prospector Problem (General Case) | Nov 11, 2017 |

Linked List Problem in C | Nov 7, 2009 |

**Physics Forums - The Fusion of Science and Community**