Responsive Ads Here

Tuesday, 13 June 2017

Delete nodes having greater value on right

problem id:--http://practice.geeksforgeeks.org/problems/delete-nodes-having-greater-value-on-right/1


code::--

/*

The structure of linked list is the following

struct Node
{
int data;
Node* next;
};

*/
int m;
Node *ans;
void magic(Node *root)
    {
    if(root==NULL)  return ;
    magic(root->next);
    if(root->data >=m)
        {
        m=root->data;
        root->next=ans;
        ans=root;
        }
    }
Node *compute(Node *head)
{
m=0;
ans=NULL;
magic(head);
return ans;
}

No comments:

Post a Comment