void main() { int a[M],s,n,i; printf("Enter the number of elements\n "); scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); hash(a,n); printf("Enter element to search "); scanf("%d",&s); if(dehash(a,s)==1) printf("FOUND"); else printf("NOT"); }
/* transform the graph to a shortest-path tree by marking tree edges */ void mapit() { register p_node n; register p_link l; p_link lparent; static int firsttime = 0; vprintf(stderr, "*** mapping\n"); Tflag = Tflag && Vflag; /* tracing here only if verbose */ /* re-use the hash table space for the heap */ Heap = (p_link *) Table; Hashpart = pack(0L, Tabsize - 1); /* expunge penalties from -a option and make circular copy lists */ resetnodes(); if (firsttime++) { if (Linkout && *Linkout) /* dump cheapest links */ showlinks(); if (Graphout && *Graphout) /* dump the edge list */ dumpgraph(); } /* insert Home to get things started */ l = newlink(); /* link to get things started */ getlink(l)->l_to = Home; (void) dehash(Home); insert(l); /* main mapping loop */ remap: Heaphighwater = Nheap; while ((lparent = min_node()) != 0) { chkheap(1); getlink(lparent)->l_flag |= LTREE; n = getlink(lparent)->l_to; if (Tflag && maptrace(n, n)) fprintf(stderr, "%s -> %s mapped\n", getnode(getnode(n)->n_parent)->n_name, getnode(n)->n_name); if (getnode(n)->n_flag & MAPPED) die("mapped node in heap"); getnode(n)->n_flag |= MAPPED; /* add children to heap */ heapchildren(n); } vprintf(stderr, "heap high water mark was %ld\n", Heaphighwater); /* sanity check on implementation */ if (Nheap != 0) die("null entry in heap"); if (Hashpart < Tabsize) { /* * add back links from unreachable hosts to * reachable neighbors, then remap. * * asymptotically, this is quadratic; in * practice, this is done once or twice. */ backlinks(); if (Nheap) goto remap; } if (Hashpart < Tabsize) { fputs("You can't get there from here:\n", stderr); for ( ; Hashpart < Tabsize; Hashpart++) { fprintf(stderr, "\t%s", getnode(Table[Hashpart])->n_name); if (getnode(Table[Hashpart])->n_flag & ISPRIVATE) fputs(" (private)", stderr); putc('\n', stderr); } } }