Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Wednesday, January 3, 2018

Delete Every kth element LinkedList


Code:

 Node delete(Node head, int k)
    {
int c=2;  
Node cur=head;
while(head!=null && head.next!=null)
{
    if(c==k)
    {
        c=1;
        head.next=head.next.next;
    }
    ++c;
    head=head.next;
}
return cur;
    }

0 Comments:

Post a Comment

Stats