Introduction to the algorithm 11.4 open addressing method (except Fahahi function open addressing handling conflict)

Source: Internet
Author: User

/* * ia_11.4openaddressing.cpp * * Created on:feb, * author:sunyj * * * #include <stdint.h> #include <  String.h> #include <iostream>class Node {public:node () {} node (int64_t const K, int64_t const D): Key (k),    Data (d) {} int64_t key; int64_t data;}; Class Openaddressinglinerprob {public:openaddressinglinerprob (int64_t const N): Length (n) {data = new Node N        ();    memset (data,-1, n * sizeof (Node));    } int64_t Hashfunc (int64_t const key) {return key% length;            } Node Hashfunclinerprobsearch (int64_t const key) {for (int64_t i = 0; i < length; i++) {            if (Data[hashfunc (key) + I].key = = key) {return Data[hashfunc (key) + i];    }} return Node ();  } void Hashfunclinerprobinsert (Node const x) {for (int64_t i = 0; i < length; i++) {if            (Data[hashfunc (x.key) + I].key = =-1)            {    Data[hashfunc (X.key) + i] = x;            return;    }}}private:node* data; int64_t length;};    int main () {Openaddressinglinerprob linertable (7);    Node Node2 (2, 200);    Node Node3 (5, 300);    Node Node9 (9, 900);    Node Node4 (4, 400); Linertable.    Hashfunclinerprobinsert (Node2); Linertable.    Hashfunclinerprobinsert (NODE3); Linertable.    Hashfunclinerprobinsert (NODE9); Linertable.    Hashfunclinerprobinsert (NODE4); Node tmp = linertable.    Hashfunclinerprobsearch (4);    Std::cout << tmp.data << Std::endl; TMP = linertable.    Hashfunclinerprobsearch (2);    Std::cout << tmp.data << Std::endl; TMP = linertable.    Hashfunclinerprobsearch (9);    Std::cout << tmp.data << Std::endl; return 0;} Linear probing

Introduction to the algorithm 11.4 open addressing method (except Fahahi function open addressing handling conflict)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.