Skip to content

Instantly share code, notes, and snippets.

@luis-l
Last active August 29, 2015 14:07
Show Gist options
  • Save luis-l/fdfb455f89f07f31464a to your computer and use it in GitHub Desktop.
Save luis-l/fdfb455f89f07f31464a to your computer and use it in GitHub Desktop.
void remove(int x)
{
node *p=top;
node *q=NULL;
while(p!=NULL)
{
if(p->data==x)
q=p;
p=p->next;
}
removeNode(q);
}
void removeNode(node* target){
if(target==top)
removeFront();
else if(target==bottom)
removeBack();
//some node in between
else
{
target->prev->next=target->next;
target->next->prev=target->prev;
delete target;
}
}
void tricmate()
{
int counter = 1;
node* current = top;
node* next;
while(current != NULL){
next = current->next; //save next node
//third element found
if(counter == 3){
counter = 0; //reset counter
removeNode(current);
}
current = next;
counter++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment