Pagini recente » Cod sursa (job #865196) | Cod sursa (job #1500936) | Cod sursa (job #1614189) | Cod sursa (job #1252657) | Cod sursa (job #3155005)
#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);
}
}