i have created my code.But my division is not working for longer number.CAn anybody solve this.
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <sstream>
#include <iomanip>
using std::setfill;
using std::setw;
using namespace std;
void subtract (struct head *oprnd1, struct head *oprnd2, struct head *result);
void add (struct head *oprnd1, struct head *oprnd2, struct head *result);
struct node
{
long int data;
struct node *llink;
struct node *rlink;
node ()
{
data = 0;
llink = NULL;
rlink = NULL;
}
};
struct head
{
int noofdigit;
char sign;
struct node *left;
struct node *right;
head ()
{
noofdigit = 0;
sign=0;
left = NULL;
right = NULL;
}
};
void makenull (struct head *temphead)
{
struct node *ptr;
ptr = temphead->right;
free (temphead);
while (ptr->rlink != NULL)
{
free (ptr);
ptr = ptr->rlink;
}
}
char sign (struct head *temphead)
{
return (temphead->sign);
}
int digits (struct head *temphead)
{
return (temphead->noofdigit);
}
node* firstright (struct head *temphead)
{
return (temphead->left);
}
node* firstleft (struct head *temphead)
{
return (temphead->right);
}
node* nextright (struct node *tempnode)
{
return (tempnode->rlink);
}
node* nextleft (struct node *tempnode)
{
return (tempnode->llink);
}
void insertright (struct head *temphead, struct node *tempnode)
{
struct node *rightmost;
// cout <<"insertright "<<tempnode->data<<endl;
if ((temphead->left == NULL) && (temphead->right == NULL))
{
temphead->right = tempnode;
temphead->left = tempnode;
// tempnode->llink = temphead;
// tempnode->rlink = NULL;
}
else
{
rightmost = temphead->left;
// cout<<"insertright:rightmost="<<rightmost->data<<endl;
rightmost->rlink = tempnode;
tempnode->llink = rightmost;
tempnode->rlink = NULL;
temphead->left = tempnode;
// cout<<"insertright:tempnode created "<<endl;
}
}
void insertleft (struct head *temphead, struct node *tempnode)
{
struct node *leftmost;
// cout <<"insertleft "<<tempnode->data<<endl;
if ((temphead->left == NULL) && (temphead->right == NULL))
{
temphead->right = tempnode;
temphead->left = tempnode;
// tempnode->rlink = NULL;
}
else
{
leftmost = temphead->right;
// cout<<"insertleft:leftmost="<<leftmost->data<<endl;
leftmost->llink = tempnode;
tempnode->rlink = leftmost;
tempnode->llink = NULL;
temphead->right = tempnode;
// cout<<"insertleft:tempnode created"<<endl;
}
}
int overflow (struct node *tempnode)
{
long int ovrflwdgt = 0;
ovrflwdgt = tempnode->data / 100000000;
if (ovrflwdgt != 0)
{
tempnode->data = tempnode->data - (ovrflwdgt * 100000000);
}
return ovrflwdgt;
}
void createlist (string num, struct head *temphead)
{
struct node *tempnode;
string tempnum,t1;
int numnodes8,remnodes8,nodenum,i;
// stringstream temps;
temphead->noofdigit = num.length () - 1;
temphead->sign = num[0];
// cout << temphead->noofdigit <<endl;
// cout << temphead->sign <<endl;
tempnum = num.substr (1, temphead->noofdigit);
// tempnum = tempnum.reverse();
// cout <<"tempnum = "<<tempnum<<endl;
numnodes8 = temphead->noofdigit / 8;
remnodes8 = temphead->noofdigit % 8;
// cout <<"numnodes8 = "<<numnodes8<<endl;
// cout <<"remnodes8 = "<<remnodes8<<endl;
if (remnodes8 > 0)
{
t1 = tempnum.substr(0,remnodes8);
stringstream temps(t1);
temps >> nodenum;
// cout <<"nodenum="<<nodenum<<endl;
tempnode = new struct node;
tempnode->data = nodenum;
insertright (temphead,tempnode);
}
for (i=remnodes8;i<tempnum.length();i=i+8)
{
t1 = tempnum.substr(i,8);
// cout <<"t1="<<t1<<endl;
stringstream temps(t1);
temps >> nodenum;
// cout <<"remnode nodenum="<<nodenum<<endl;
tempnode = new struct node;
tempnode->data = nodenum;
insertright (temphead,tempnode);
}
}
int bigger (struct head *head1, struct head *head2)
{
struct node *ptr1, *ptr2;
// cout << "oprnd1 numdigit "<<head1->noofdigit<<" oprnd2 "<<head2->noofdigit<<endl;
if (head1->noofdigit > head2->noofdigit)
{
// cout <<"big: oprnd1 big"<<endl;
return 1;
}
else if (head1->noofdigit < head2->noofdigit)
{
// cout <<"big: oprnd2 big"<<endl;
return 0;
}
else
{
// cout <<"big same size"<<endl;
ptr1 = head1->right;
ptr2 = head2->right;
while (ptr1 != NULL && ptr2 != NULL)
{
// cout <<"big="<<ptr1->data<<" "<<ptr2->data<<endl;
if (ptr1->data > ptr2->data)
{
return 1;
}
else if (ptr1->data < ptr2->data)
{
return 0;
}
else
{
ptr1 = ptr1->rlink;
ptr2 = ptr2->rlink;
}
}
}
return 1;
}
int finddigit (struct head *head1)
{
int count1=0;
long int num;
struct node *ptr;
ptr = new struct node;
ptr = firstleft (head1);
// cout <<"IN Find digit"<<endl;
while (ptr != NULL)
{
num = ptr->data;
// cout <<"num="<<num<<endl;
while (num > 0)
{
count1++;
num = num / 10;
}
ptr = ptr->rlink;
}
// cout<<"NUM digits="<<count1<<endl;
return count1;
}
void display (struct head *head1)
{
struct node *ptr;
// cout <<"DISPLAY"<<endl;
if (head1->right != NULL && head1->left != NULL)
{
ptr = head1->right;
// cout <<"head1="<<head1->noofdigit<<endl;
// cout <<"NUMBER"<<endl;
cout << head1->sign;
cout << ptr->data;
ptr = ptr->rlink;
cout << right;
while (ptr != NULL)
{
cout.fill('0');
cout << setw(8) << dec;
cout << ptr->data;
ptr = ptr->rlink;
}
cout << endl;
}
}
void subtract (struct head *oprnd1, struct head *oprnd2, struct head *result)
{
struct node *n1, *n2, *rslt;
struct head *tempswap;
long int diff, carryover = 0;
// cout<<"IN SUBTRACT"<<endl;
if (sign (oprnd1) == sign (oprnd2))
{
if (bigger (oprnd2,oprnd1) == 1)
{
// cout <<"oprnd2 is bigger"<<endl;
tempswap = oprnd2;
oprnd2 = oprnd1;
oprnd1 = tempswap;
if (result->sign == '-' || result->sign == '+')
{
// cout <<"same sign"<<endl;
}
else
{
// cout <<"diff sign"<<endl;
result->sign = sign (oprnd2);
}
// cout << "bigger oprnd2"<<endl;
}
else
{
if (result->sign == '-' || result->sign == '+')
{
}
else
{
result->sign = sign (oprnd1);
}
}
n1 = firstright (oprnd1);
n2 = firstright (oprnd2);
// cout<<"n1="<<n1->data<<" n2="<<n2->data<<endl;
while (n1 != NULL && n2 != NULL)
{
if ((n1->data - carryover) >= n2->data)
{
diff = (n1->data - carryover) - n2->data;
// cout << "diff="<<diff<<endl;
rslt = new struct node;
rslt->data = diff;
insertleft (result, rslt);
}
else
{
diff = (100000000 + n1->data - carryover) - n2->data;
// cout <<"less diff="<<diff<<endl;
rslt = new struct node;
rslt->data = diff;
insertleft (result, rslt);
carryover = 1;
}
n1 = nextleft (n1);
n2 = nextleft (n2);
}
}
else
{
if (bigger (oprnd1, oprnd2) == 1)
{
if (sign (oprnd1) == '+')
{
result->sign = sign (oprnd1);
oprnd2->sign = '+';
add (oprnd1, oprnd2, result);
}
else
{
result->sign = sign (oprnd1);
oprnd1->sign = '+';
add (oprnd1, oprnd2, result);
}
}
else
{
if (sign (oprnd2) == '+')
{
result->sign = sign (oprnd2);
oprnd1->sign = '+';
subtract (oprnd1, oprnd2, result);
}
else
{
result->sign = sign (oprnd2);
oprnd2->sign = '+';
add (oprnd1, oprnd2, result);
}
}
}
display (result);
}
void add (struct head *oprnd1, struct head *oprnd2, struct head *result)
{
struct node *n1, *n2, *rslt;
struct head *tempswap;
long int sum, ovrflwdgt = 0;
// cout<<"IN ADD"<<endl;
if (sign (oprnd1) == sign (oprnd2))
{
cout <<"add in1"<<endl;
n1 = firstright (oprnd1);
// cout <<"in1:n1="<<n1->data<<endl;
n2 = firstright (oprnd2);
// cout <<"in1:n2="<<n2->data<<endl;
cout<<"n1="<<n1->data<<" n2="<<n2->data<<endl;
while (n1 != NULL && n2 != NULL)
{
sum = n1->data + n2->data + ovrflwdgt;
// cout<<"sum="<<sum<<endl;
rslt = new struct node;
rslt->data = sum;
// cout<<"result="<<rslt->data<<endl;
insertleft (result,rslt);
// cout<<"after insertleft"<<endl;
ovrflwdgt = overflow(rslt);
// cout<<"overflow="<<ovrflwdgt<<endl;
n1 = nextleft (n1);
n2 = nextleft (n2);
}
while (n1 != NULL)
{
sum = n1->data + ovrflwdgt;
rslt = new struct node;
rslt->data = sum;
insertleft (result, rslt);
ovrflwdgt = overflow (rslt);
n1 = nextleft (n1);
}
while (n2 != NULL)
{
sum = n2->data + ovrflwdgt;
rslt = new struct node;
rslt->data = sum;
insertleft (result, rslt);
ovrflwdgt = overflow (rslt);
n2 = nextleft (n2);
}
if (ovrflwdgt > 0)
{
rslt = new struct node;
rslt->data = ovrflwdgt;
// cout<<"overflow present"<<endl;
insertleft (result, rslt);
}
if (result->sign == '-' || result->sign == '+')
{
}
else
{
result->sign = sign (oprnd1);
}
}
else
{
if (bigger (oprnd2,oprnd1) == 1)
{
tempswap = oprnd2;
oprnd2 = oprnd1;
oprnd1 = tempswap;
result->sign = sign (oprnd2);
oprnd1->sign = '+';
oprnd2->sign = '+';
// cout <<"add bigger oprnd2"<<endl;
}
else
{
result->sign = sign (oprnd1);
oprnd1->sign = '+';
oprnd2->sign = '+';
// cout <<"add bigger oprnd1"<<endl;
}
subtract (oprnd1,oprnd2,result);
}
display (result);
}
struct head* multiply (struct head *oprnd1, struct head *oprnd2, struct head *result)
{
struct node *n1, *n2, *rslt;
struct head *temp1,*temp2, *result1, *temp11, *temp12;;
long int ovrflwdgt = 0, digitsnode = -1,i,digits=1, num1, num2, num, first=0, rem, firstnode = 0,nodenum=0;
long long int mult;
// cout <<"IN MULTIPLY"<<endl;
n1 = firstright (oprnd1);
n2 = firstright (oprnd2);
cout <<"right "<<n1->data<<" "<<n2->data<<endl;
// digitsnode = 0;
while (n1 != NULL)
{
cout<<"in1"<<endl;
// n2 = firstright (oprnd2);
digitsnode=nodenum;
nodenum++;
// cout<<"in1:digitsnodes="<<digitsnode<<endl;
while (n2 != NULL)
{
// cout<<"in2 n2="<<n2->data<<"n1="<<n1->data<<endl;
/* temp1 = new struct head;
temp1->sign = '+';
temp2 = new struct head;
temp2->sign = '+';
for (i=0;i<digitsnode;i++)
{
rslt = new struct node;
rslt->data = 0;
insertleft (temp1,rslt);
}
*/
// cout <<"MULTIPLY: calling multiplynodes"<<endl;
// multiplynodes (n1,n2,result1);
// result1 = new struct head;
// result1->sign = '+';
result1 = new struct head;
result1->sign = '+';
result1->left = NULL;
result1->right = NULL;
num1 = n1->data;
num2 = n2->data;
// cout<<"num1="<<num1<<" num2="<<num2<<endl;
digits = 1;
first = 0;
while (num1 > 0)
{
// cout<<"multiplynode:first result1 "<<endl;
// display (result1);
temp11 = new struct head;
temp12 = new struct head;
temp11->sign = '+';
temp12->sign = '+';
num = num1 % 10;
mult = num2 * num;
// if (digits > 100)
// {
rem = (mult % (100000000 / digits));
rslt = new struct node;
cout<<"rem="<<rem<<" digits="<<digits<<endl;
rslt->data = rem * digits;
// cout<<"calling insertleft"<<endl;
insertleft (temp11, rslt);
ovrflwdgt = mult / (100000000 / digits);
// cout<<"overflow="<<ovrflwdgt<<endl;
if (ovrflwdgt > 0)
{
rem = ovrflwdgt;
rslt = new struct node;
rslt->data = rem;
// cout<<"Calling insertleft overflow"<<endl;
insertleft (temp11, rslt);
}
// }
if (first == 0)
{
temp12 = temp11;
first = 1;
}
else
{
// cout<<"calling add in multiplynodes"<<endl;
display (temp11);
display (result);
add (temp11, result1, temp12);
}
num1 = num1 / 10;
digits = digits * 10;
result1 = temp12;
}
// cout<<"MULTIPLY: result1 n1 n2 "<<n1->data<<" "<<n2->data<<endl;
display (result1);
if (firstnode == 0)
{
// here temp1 = result1;
result = result1;
firstnode = 1;
}
else
{
// cout <<"MULTIPLY: call add temp1 result digitsnode="<<digitsnode<<endl;
for (i=0;i<digitsnode;i++)
{
rslt = new struct node;
rslt->data = 0;
insertright (result1,rslt);
}
// here display (temp1);
display (result1);
temp2 = new struct head;
temp2->sign = '+';
add (result,result1,temp2);
// here temp1 = temp2;
result = temp2;
// cout<<"check this result"<<endl;display (result);
}
// makenull (temp1);
// makenull (temp2);
digitsnode++;
n2 = nextleft (n2);
}
// cout <<"outside n2 loop"<<endl;
n1 = nextleft (n1);
n2 = firstright (oprnd2);
// cout<<"checking n2="<<n2->data<<endl;
// nodenum++;
// digitsnode = 0;
}
// digitsnode=0;
// result = temp1;
// cout <<"IN MULTIPLY FINAL="<<endl;
// display (result1);
// display (result);
return result;
}
long int divide (struct head *oprnd1, struct head *oprnd2, struct head *result)
{
struct node *n1, *n2, *rslt;
struct head *temp1, *temp2, *result1, *zerolist;
long int num1, num2, quotient=0;
// cout <<"IN DIVIDE"<<endl;
// n1 = firstright (oprnd1);
// n2 = firstright (oprnd2);
temp1 = new struct head;
temp2 = new struct head;
temp1 = oprnd1;
temp2 = oprnd2;
// cout <<"temp1"<<endl;
display (temp1);
// cout <<"temp2"<<endl;
display (temp2);
zerolist = new struct head;
rslt = new struct node;
rslt->data = 0;
insertleft (zerolist, rslt);
do
{
result1 = new struct head;
result1->sign = '+';
// cout<<"calling subtract temp1 temp2"<<endl;
display (temp1);
display (temp2);
subtract (temp1, temp2, result1);
result1->noofdigit = finddigit (result1);
result1->sign = '+';
// cout <<"divide result1="<<endl;display (result1);
temp1 = result1;
temp2 = oprnd2;
quotient++;
}while (bigger (result1, oprnd2) == 1);
// cout <<"Quotient="<<quotient<<endl;
return quotient;
}
struct head* power (struct head *oprnd1, int i)
{
struct head *n1, *n2, *result1;
int j,x=1,num;
// cout <<"IN POWER"<<endl;
num = i;
n1 = new struct head;
n2 = new struct head;
result1 = new struct head;
n1 = oprnd1;
n2 = oprnd1;
while (num > 1)
{
// cout<<"POWER num="<<num<<endl;
display (n1);
result1 = new struct head;
result1 = multiply (n1,n1,result1);
// cout<<"POWER result1"<<endl;
display (result1);
n1 = result1;
num = num / 2;
x = x * 2;
}
// cout<<"POWER x="<<x<<endl;
// result1 = new struct head;
for (j=0;j<(i-x);j++)
{
// cout<<"POWER in"<<endl;
display (n1);
display (n2);
result1 = new struct head;
result1 = multiply (n1,n2,result1);
// cout<<"result1"<<endl;display (result1);
n1 = result1;
n2 = oprnd1;
}
// cout<<"POWER is"<<endl;
display (result1);
return result1;
}
int main ()
{
char *in;
int ch = 0, powernum;
string num1,num2;
long int quot;
struct node *rslt;
struct head *oprnd1,*oprnd2,*result,*temp;
struct head *listA,*listB,*listC,*listD,*listE,*listF,*listG,*listH,*listI,*listJ,*listK,*listL,*listM,*listN,*listO,*listP,*listQ,*listR,*listS,*listT,*listU,*listV,*listW,*listX,*listY,*listZ;
// cout <<"hello"<<endl;
while (ch != 7)
{
cout <<"1 Add"<<endl;
cout <<"2 Subtract"<<endl;
cout <<"3 Multiply"<<endl;
cout <<"4 Divide"<<endl;
cout <<"5 Pow"<<endl;
cout <<"6 Using given data"<<endl;
cout <<"7 Exit"<<endl;
cout <<"Enter your choice: ";
cin >>ch;
cout <<ch<<endl;
switch (ch)
{
case 1:
cout <<"Addition!"<<endl;
// getline (cin, num1);
cout <<"Enter operand1: ";
cin >> num1;
cout <<num1<<endl;
oprnd1 = new struct head;
createlist (num1,oprnd1);
// cout<<"oprnd1"<<oprnd1->noofdigit<<endl;
display (oprnd1);
cout <<"Enter operand2: ";
cin >> num2;
oprnd2 = new struct head;
createlist (num2,oprnd2);
display (oprnd2);
result = new struct head;
add (oprnd1,oprnd2,result);
cout<<"ADD FINAL"<<endl;display (result);
break;
case 2:
cout <<"Subtraction!"<<endl;
cout <<"Enter operand1: ";
cin >> num1;
cout <<num1<<endl;
oprnd1 = new struct head;
createlist (num1,oprnd1);
// cout<<"oprnd1"<<oprnd1->noofdigit<<endl;
display (oprnd1);
cout <<"Enter operand2: ";
cin >> num2;
oprnd2 = new struct head;
createlist (num2,oprnd2);
display (oprnd2);
result = new struct head;
subtract (oprnd1,oprnd2,result);
cout<<"SUBTRACT FINAL"<<endl;display (result);
break;
case 3:
cout <<"Multiplication!"<<endl;
cout <<"Enter operand1: ";
cin >> num1;
cout <<num1<<endl;
oprnd1 = new struct head;
createlist (num1,oprnd1);
// cout<<"oprnd1"<<oprnd1->noofdigit<<endl;
display (oprnd1);
cout <<"Enter operand2: ";
cin >> num2;
oprnd2 = new struct head;
createlist (num2,oprnd2);
display (oprnd2);
result = new struct head;
result->sign = '+';
temp = new struct head;
temp=multiply (oprnd1,oprnd2,result);
cout<<"MULTIPLY FINAL"<<endl;display (result);cout<<"temp"<<endl;display (temp);
break;
case 4:
cout <<"Division!"<<endl;
cout <<"Enter operand1: ";
cin >> num1;
cout <<num1<<endl;
oprnd1 = new struct head;
createlist (num1,oprnd1);
// cout<<"oprnd1"<<oprnd1->noofdigit<<endl;
display (oprnd1);
cout <<"Enter operand2: ";
cin >> num2;
oprnd2 = new struct head;
createlist (num2,oprnd2);
display (oprnd2);
result = new struct head;
result->sign = '+';
quot = divide (oprnd1,oprnd2,result);
cout<<"DIVISION FINAL="<<quot<<endl;
break;
case 5:
cout <<"Power!"<<endl;
cout <<"Enter the number: ";
cin >> num1;
cout <<num1<<endl;
oprnd1 = new struct head;
createlist (num1, oprnd1);
// cout <<"oprnd1"<<oprnd1->noofdigit<<endl;
display (oprnd1);
cout <<"Enter the power: ";
cin >> powernum;
result = new struct head;
result->sign = '+';
result = power (oprnd1, powernum);
cout<<"POWER OUT"<<endl;display(result);
break;
case 6:
cout <<"Given!"<<endl;
listA = new struct head;
listB = new struct head;
listC = new struct head;
listD = new struct head;
listE = new struct head;
listF = new struct head;
listG = new struct head;
listH = new struct head;
listI = new struct head;
listJ = new struct head;
listK = new struct head;
listL = new struct head;
listM = new struct head;
listN = new struct head;
listO = new struct head;
listP = new struct head;
listQ = new struct head;
listR = new struct head;
listS = new struct head;
listT = new struct head;
listU = new struct head;
listV = new struct head;
listW = new struct head;
listX = new struct head;
listY = new struct head;
listZ = new struct head;
rslt = new struct node;
rslt->data = 22222222;
insertleft (listA, rslt);
rslt = new struct node;
rslt->data = 55555555;
insertleft (listB, rslt);
rslt = new struct node;
rslt->data = 24681357;
insertleft (listC, rslt);
rslt = new struct node;
rslt->data = 18027036;
insertleft (listD, rslt);
listE->sign = '+';
cout<<"Given E = A * D"<<endl;
listE = multiply (listA,listD,listE);
cout<<"listE"<<endl;
display (listE);
listF->sign = '+';
cout<<"F = A ^ 2"<<endl;
listF = power (listA,2);
cout<<"listF"<<endl;
display (listF);
listG->sign = '+';
cout<<"G = D ^ 2"<<endl;
listG = power (listD,2);
cout<<"listG"<<endl;
display (listG);
listH->sign = '+';
cout<<"H = B * C"<<endl;
listH = multiply (listB,listC,listH);
cout<<"listH"<<endl;
display (listH);
listI->sign = '+';
cout<<"I = A + D"<<endl;
add (listA,listD,listI);
cout<<"listI"<<endl;
display (listI);
listJ->sign = '+';
cout<<"J = I ^ 2"<<endl;
listJ = power (listI,2);
cout<<"listJ"<<endl;
display (listJ);
listK->sign = '+';
cout<<"K = J - F"<<endl;
display (listJ);display(listF);
subtract (listJ,listF,listK);
cout<<"listK"<<endl;
display (listK);
listL->sign = '+';
cout<<"Given L = K - G"<<endl;
subtract (listK, listG, listL);
cout<<"listL"<<endl;
display (listL);
listM->sign = '+';
cout<<"M = L / E"<<endl;
quot = divide (listL,listE,listM);
rslt = new struct node;
rslt->data = quot;
insertleft (listM,rslt);
cout<<"listM"<<endl;
display(listM);
cout<<"Delete"<<endl;
makenull (listF);
makenull (listG);
makenull (listI);
makenull (listJ);
makenull (listK);
makenull (listL);
makenull (listM);
listN->sign = '+';
cout<<"N = E ^ 2"<<endl;
listN = power (listE,5);
cout<<"listN"<<endl;
display (listN);
listO->sign = '+';
cout<<"O = H ^ 3"<<endl;
listO = power (listH, 3);
cout<<"listO"<<endl;
display (listO);
listP->sign = '+';
cout<<"P = N - O"<<endl;
subtract(listN,listO,listP);
cout<<"listP"<<endl;
display (listP);
listQ->sign = '+';
cout<<"Q = N ^ 2"<<endl;
listQ = power (listN,2);
cout<<"listQ"<<endl;
display (listQ);
listR->sign = '+';
cout<<"R = O ^ 2"<<endl;
listR = power (listO,2);
cout<<"listR"<<endl;
display (listR);
listS->sign = '+';
cout<<"S = Q - R"<<endl;
subtract(listQ,listR,listS);
cout<<"lists"<<endl;
display (listS);
listT->sign = '+';
cout<<"T = S / P"<<endl;
quot = divide (listS,listP,listT);
rslt = new struct node;
rslt->data = quot;
insertleft (listT,rslt);
cout<<"listT"<<endl;
display (listT);
listU->sign = '+';
cout<<"U = T - O"<<endl;
subtract(listT,listO,listU);
cout<<"listU"<<endl;
display (listU);
listV->sign = '+';
cout<<"V = U - N"<<endl;
subtract(listU,listN,listV);
cout<<"listV"<<endl;
display (listV);
listW->sign = '+';
cout<<"W = C ^ 2"<<endl;
listW = power (listC,2);
cout<<"listW"<<endl;
display (listW);
listX->sign = '+';
cout<<"X = B ^ 2"<<endl;
listX = power (listB,2);
cout<<"listX"<<endl;
display (listX);
listY->sign = '+';
cout<<"Y = W - X"<<endl;
subtract(listW,listX,listY);
cout<<"listY"<<endl;
display (listY);
listZ->sign = '+';
cout<<"Z = C + B"<<endl;
add(listC,listB,listZ);
cout<<"listZ"<<endl;
display (listZ);
listH = new struct head;
listH->sign = '+';
cout<<"H = Y / Z"<<endl;
quot = divide (listY,listZ,listH);
rslt = new struct node;
rslt->data = quot;
insertleft(listH,rslt);
cout<<"listH"<<endl;
display (listH);
listF = new struct head;
listF->sign = '+';
cout<<"F = N ^ 5"<<endl;
listF = power (listN,5);
cout<<"listF"<<endl;
display (listF);
listG = new struct head;
listG->sign = '+';
cout<<"G = E ^ 25"<<endl;
listG = power (listE,25);
cout<<"listG"<<endl;
display (listG);
listI = new struct head;
listI->sign = '+';
cout<<"I = F / N"<<endl;
quot = divide (listF,listN,listI);
rslt = new struct node;
rslt->data = quot;
insertleft(listI,rslt);
cout<<"listI"<<endl;
display (listI);
listJ = new struct head;
listJ->sign = '+';
cout<<"J = G / I"<<endl;
quot = divide (listG,listI,listJ);
rslt = new struct node;
rslt->data = quot;
insertleft(listJ,rslt);
cout<<"listJ"<<endl;
display (listJ);
listM = new struct head;
listM->sign = '+';
cout<<"M = N ^ 10"<<endl;
listM = power (listN,10);
cout<<"listM"<<endl;
display (listM);
makenull (listP);
listP = new struct head;
listP->sign = '+';
cout<<"P = G ^ 2"<<endl;
listP = power (listG,2);
cout<<"listP"<<endl;
display (listP);
makenull (listQ);
makenull (listR);
listQ = new struct head;
listQ->sign = '+';
cout<<"Q = P - M"<<endl;
subtract(listP,listM,listQ);
cout<<"listQ"<<endl;
display (listQ);
listR = new struct head;
listR->sign = '+';
cout<<"R = J - M"<<endl;
subtract(listJ,listM,listR);
cout<<"listR"<<endl;
display (listR);
break;
}
}
}