Skip to content

Instantly share code, notes, and snippets.

@oskimura
Created August 23, 2016 09:25
Show Gist options
  • Save oskimura/18e8dd160dfc4a4bf16ec77826d42dd0 to your computer and use it in GitHub Desktop.
Save oskimura/18e8dd160dfc4a4bf16ec77826d42dd0 to your computer and use it in GitHub Desktop.
#include <stdio.h>
template <typename T>
class bilst
{
struct node {
node *next;
node *prev;
T val;
};
node* nil;
void insert(T e)
{
node* n = new node();
n->val = e;
n->next = nil->next;
nil->next->prev = n;
nil->next = n;
n->prev = nil;
}
void del(T e)
{
node* n = new node();
n->val = e;
n->prev->next = n->next;
n->next->prev = n->prev;
}
bool search(T e) {
node x = nil->next;
while (x != nil) {
if (x->val == e.val) {
return true;
}
x = x->next;
}
return false;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment