Pagini recente » Cod sursa (job #2177165) | Cod sursa (job #1409771) | Cod sursa (job #2715487) | Cod sursa (job #422527) | Cod sursa (job #582567)
Cod sursa(job #582567)
#include <stdio.h>
#define M 11
int n;
struct node {
int info;
node *next;
} **H;
node* search(int x) {
node *c;
for(c = H[x%M];c && c->info != x;c=c->next);
return c;
}
void add(int x) {
node *c;
c = search(x);
if(c == NULL) {
c = new node;
c->info = x;
c->next = H[x%M];
H[x%M] = c;
}
}
void deleteNode(int x) {
node *c, *p;
for(c = H[x%M];c && c->info != x;p=c, c=c->next);
if(c == H[x%M] && c!= NULL) {
H[x%M] = c->next;
delete c;
return;
}
if(c) {
p->next = c->next;
delete c;
}
}
int main() {
int x,i,op;
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
scanf("%d", &n);
H = new node*[M];
for(i=0;i<M;i++) {
H[i] = NULL;
}
for(i=0;i<n;i++) {
scanf("%d %d", &op, &x);
switch(op) {
case 1: add(x); break;
case 2: deleteNode(x); break;
case 3: printf("%d\n", search(x) == NULL ? 0 : 1);
}
}
return 0;
}