Cod sursa(job #1191765)

Utilizator heracleRadu Muntean heracle Data 28 mai 2014 17:43:12
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.47 kb
#include <iostream>

template  <unsigned int KEY ,unsigned int nrelem , class T = unsigned int> struct hash
{
    unsigned int urm[nrelem+1];
    unsigned int lst[nrelem+1];
    T val[KEY];
    int nr;

    bool contains(T x)
    {
        int p=lst[x%KEY];
        while(p!=0)
        {
            if(val[p]==x)
                return 1;
            p=urm[p];
        }
        return 0;
    }

    void clean()
    {
        for(int i=0; i<KEY; i++)
            lst[i]=0;
        nr=0;
    }

    void add(T x)
    {
        int p=x%KEY;
        nr++;
        val[nr]=x;
        urm[nr]=lst[p];
        lst[p]=nr;
    }

    void sterge(T x)
    {
        int p=lst[x%KEY];

        if(x==val[p])
        {
            lst[x%KEY]=urm[p];
            return;
        }
        while(p!=0 && val[urm[p]]!=x)
        {
            p=urm[p];
        }
        if(val[p]==x)
        {
            urm[p]=urm[urm[p]];
        }
    }
    void sterge_tot(T x)
    {
        int p=lst[x%KEY];

        if(x==val[p])
        {
            lst[x%KEY]=urm[p];
            p=urm[p];
        }

        while(p!=0)
        {
            if(val[urm[p]]==x)
            {
                urm[p]=urm[urm[p]];
            }
            p=urm[p];
        }
    }

};

FILE* in;
FILE* out;

hash< 1<<20 , 1000000 >;

int main()
{
    in=fopen("hashuri.in","r");
    out=fopen("hashuri.out","w");

    int t;




    return 0;
}