You are on page 1of 1

DSA LAB 07 (Stack + Linked List) BS F13-Aft, BIT F13

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Task 1: Using Stack write function int evaluate(string exp) to solve and return result of Post-fix
expression (discussed in class), Below is the main code to test function with required output?
Note: It’s better to take integer type stack and subtract '0 ' while push instead of pop.
Output: int main()
236*+:20 {
23+6*:30 string s[]={"236*+","23+6*","236+4*-","293/+4*2-","23621463/+*-+*-"};
236+4*-:-34 int i;
293/+4*2-:18 for (i=0;i<5;i++)
23621463/+*-+*-:-4 cout<<s[i]<<":"<<evaluate(s[i])<<'\n';
return 0;
}
Task 2: Using primitive data types we can store & handle integer within some specific range. We are going to
implement BigInteger that can store positive integer of any size. Implement this code. Add stream insertion
operator and test IO working properly.
Next overload + operator to add 2 BigIntegers and return a new object of type BigInteger.
class BigInteger struct IntNode
{ {
IntNode *first, *last; char val;
public: IntNode *next;
BigInteger() IntNode(int val)
{ {
first=last=new IntNode(0); this->val=val;
} next=null;
friend ostream& operator<<(ostream&, const }
BigInteger&); };
friend istream& operator>>(istream&, BigInteger&); int main()
}; {
istream& operator>>(istream &in, BigInteger &c) BigInteger x1;
{ cin>>x1;
IntNode *t; cout<<x1;
int temp, n, count; BigInteger x2;
string bInt; cin>>x2;
cout<<"Enter Big Integer:"; cout<<x2;
cin>>bInt; // cout<<x1+x2<<"------------------------------\n";
count=bInt.length(); return 0;
for (n=0;n<count;n++) }
{ Sample Run:
t=new IntNode(bInt[n]); Enter Big Integer:883432483200343
c.last->next=t; 883432483200343
c.last=t; Enter Big Integer:44663477732222772
} 44663477732222772
return in;
}

***************** Stack! Too Simple **************

Resource Person: Abdul Mateen PUCIT-NC

You might also like