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;
}
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