I'm trying to reverse a linked list, which has the below code.
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* current,prev,next;
prev=NULL;
current=head;
while(current!=NULL){
next=current->next;
current->next=prev;
prev=current;
current=next;
}
head=prev;
return head;
}
};
Everything looks fine to me but i'm getting error as no viable overloaded '=' next=current->next
I'm curious to know, why this error is coming out to be? kindly looking for help