Please provide me ready code for atleast multiplication of two numbers using doubly linked list ...
When I read this, it's like you're asking "please tell me how to make a cup of coffee using a deck of cards." I don't see the connection between the linked list and multiplying numbers. Can you post more information on the assignment, particularly what the linked list ha to do with it. Is it supposed to represent the numbers some how?
@dhayden. Big integers can be represented in a container by making each element represent 1 or more digits of the big number.
See http://www.cplusplus.com/forum/lounge/32041/ for several examples of bigInt classes built on an underlying std::vector container, etc.
Using a linked list is somewhat reasonable (maybe even good) as the arithmetic operations are carried out digit by digit by iterating over the elements.
@dinesh9293
You don't need to write a bigInt*bigInt function for this problem.
A simpler bigInt *= int will do.
The simplest way I've found to approach your specific problem is to allow each node to store 4 digits of the number, so base = 10,000.
If storing the least significant digits in the head node, then:
// implement multiplication using the usual "by hand" method
dlist& operator*=( dlist& A, int f )
{
f %= base;// allowing only a factor smaller than base
int product = 0;
int carry = 0;
dnode* it = A.head;
while( it )
{
product = it->x * f + carry;
it->x = product%base;
carry = product/base;
it = it->next;
}
if( carry ) A.push_back( carry );
return A;
}