Catalyst - 1 year ago 92
C Question

# Multiplying 2 numbers, represented by 2 linked lists of digits

I need some ideas for a homework assignment that I have.
Consider the following definition:

``````typedef struct listNode {
int* dataPtr;
struct listNode* next;
} ListNode;

typedef struct list {
ListNode* tail;
} List;
``````

Each list node represents a single digit.
Each number is represented by a list, but in a reversed manner: the last digit of the number is the first list-node of the list, and the first digit of the number is the last list-node of the list.

I've written the function

``````void addNumbers(List n1, List n2, List *sum);
``````

which returns a new list with the sum of the other two lists.

Now I have to write the function for multiplication:

``````void multNumbers(List n1, List n2 , List* prod);
``````

And I'm kinda stuck with how to implement it. It's not about the code, it's about how to do it.
Needless to say, we're not allowed to convert the numbers into an integer, multiply and go convert the result to a list.

Any help would be highly appreciated.

Thanks.

• Add the number to the result, using `addNumbers()`