Thông tin

Tác giả Roy Makhlouf Anthony Doeraene
Hạn chót Không có hạn chót
Giới hạn nộp bài Không có giới hạn

Tags

Đăng nhập

Add lists

You have to write a function called addLinkedLists which will add two integers, represented using reversed linked lists.

The linked lists are represented using the following structure:

typedef struct node{
    int val;
    struct node *next;
} node_t;

Examples of use

  • addLinkedLists(1->2->3->NULL, 2->3->4->NULL), the first linked list represent 321 while the second represent 432. If we add these numbers, we obtain 753, the function must thus return 3->5->7->NULL
  • addLinkedLists(9->9->9->NULL, 1->NULL), the first linked list represent 999 while the second represent 1. If we add these numbers, we obtain 1000, the function must thus return 0->0->0->1->NULL
  • addLinkedLists(5->9->2->NULL, 1->2->2->4->NULL), the first linked list represent 295 while the second represent 4221. If we add these numbers, we obtain 4516, the function must thus return 6->1->5->4->NULL

Câu hỏi 1: Add List
/*
 *@pre head1 != NULL, head2 != NULL.
 * head1, head2 sont des listes chainées représentant un nombre entier positif à l'envers sans zéros inutiles. Chaque noeud contient un naturel entre 0 et 9
 *@post retourne une liste chainée représentant la somme des nombres dans head1 et head2 (nombre écrits à l'envers) ou NULL en cas d'erreur
 */
node_t *addLinkedLists(node_t *head1, node_t *head2);
Câu hỏi 2: Méthodes auxiliaires

Ecrivez ici vos méthodes auxiliaires