Pagini recente » Cod sursa (job #335379) | Cod sursa (job #411339) | Cod sursa (job #368460) | Cod sursa (job #613907) | Cod sursa (job #3155003)
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
#define M 1000
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
typedef struct Node{
int value;
struct Node* next;
}Node;
Node* hash[M];
void insert(int v){
Node* node = (Node*) malloc(sizeof(Node));
node->value = v;
node->next = NULL;
int index = v % M;
if(hash[index] == NULL)
hash[index] = node;
else
hash[index]->next = node;
}
void sterge(int v){
int index = v % M;
Node *p = hash[index];
if(p == NULL)
return;
if(p->value == v){
free(p);
p = NULL;
return;
}
while(p->next != NULL){
if(p->next->value == v){
Node* aux = p->next;
p->next = p->next->next;
free(aux);
}
p = p->next;
}
}
void prezent(int v){
int index = v % M;
int cond = 0;
Node *p = hash[index];
while(p != NULL){
if(p->value == v)
cond = 1;
p = p->next;
}
if(cond == 1)
out << 1 << endl;
else
out << 0 << endl;
}
int main(){
int n;
in >> n;
for(int i = 0; i<n; i++){
int op, v;
in >> op >> v;
if(op == 1)
insert(v);
else if(op == 2)
sterge(v);
else
prezent(v);
}
}