# Add 1 to a number represented as linked list in C++

In this post, we will learn how to add 1 to a number represented as linked list in C++. For example 4959 is represented as (4-> 9-> 5 -> 9->9) and adding 1 to it should change it to (4->9->6->0->0).

## Add 1 to a number represented as linked list in C++

In this approach we will follow the following steps:
1. At first linked list is reversed.
2. Then we add 1 to leftmost node in the linked list. And if there is a carry, we will move to the next node. We will keep traversing until the carry is 0.
3. Finally we will again reverse our modified linked list and then return head.

```#include <bits/stdc++.h>
using namespace std;
class Node
{
public:
int data;
Node* next;
Node(int value){
data=value;
next=NULL;
}
};

{
Node * prev = NULL;
Node * next;
while (current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
return prev;
}
{
Node *temp, *prev = NULL;
int sum;
int carry = 1;
{
carry = (sum >= 10)? 1 : 0;
sum = sum % 10;
}
if (carry > 0)
temp->next = new Node(carry);
return res;
}
{
}
void printList(Node *node)
{
while (node != NULL)
{
cout << node->data;
node = node->next;
}
cout<<endl;
}
int main()
{
```input:List is 4959