I have written the following code to print the 2 polynomial using linked list.When i run this program it prints nothing in the output.And also please tell if i pass the value from main() in this way then, when again the function is called will my start1 and start2 will be changed or they will remain NULL as initialized.
#include <iostream>
using namespace std;
struct Node
{
int coeff;
int exp;
Node* next;
};
void create_Poly(int x, int y , Node *start)
{
Node *temp,*ptr;
if(start==NULL)
{
temp=new Node;
temp->coeff=x;
temp->exp=y;
temp->next=NULL;
}
else
{
ptr = start;
while(ptr->next!=NULL)
{
ptr=ptr->next;
}
temp = new Node;
temp->coeff=x;
temp->exp=y;
temp->next=NULL;
ptr->next=temp;
}
//return start;
}
void display(Node *start)
{
Node * print = start;
while(print!=NULL)
{
cout<<print->coeff<<"^"<<print->exp<<"+";
print=print->next;
}
cout<<endl;
}
int main()
{
struct Node * start1=NULL,*start2=NULL;
create_Poly(3,2,start1);
create_Poly(3,2,start1);
create_Poly(3,2,start1);
display(start1);
create_Poly(4,2,start2);
create_Poly(4,2,start2);
display(start2);
}