日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

一种数据结构 跳表skiplist

發布時間:2023/12/15 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 一种数据结构 跳表skiplist 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ? ? ?跳表是平衡樹的一種替代的數據結構,但是和紅黑樹不相同的是,跳表對于樹的平衡的實現是基于一種隨機化的算法的,這樣也就是說跳表的插入和刪除的工作是比較簡單的。?


下載地址 :?http://download.csdn.net/detail/hemmingway/4625042?


測試程序

// test.cpp //#include <iostream> #include <iomanip> #include <cstdlib> #include <time.h> #include "skiplist.h" #include "TimeCounter.h"#define TIME_START CTimeCounter* pT = new CTimeCounter() #define TIME_END ShowTime(pT->GetExecutionTime())// // Show execution time (ms) void ShowTime(__int64 nTime) {std::cout << "========================================" << std::endl;std::cout << " Total time: ";std::cout << std::fixed << std::setprecision(1) << std::setw(6);std::cout << nTime;std::cout << " ms" << std::endl << std::endl;//printf("Usage time: %I64d millisecond\n\n", nTime); //在g++中對應的是<stdint.h> int64_t, 應該用%lld輸出 }int main(){int count = 10, i; SkipList sl;srand((unsigned)time(NULL));std::cout<<"### Function Test ###\n\n";std::cout<<"\n=== Init Skip List ===\n\n";sl.Init();for ( i = 0; i < count; i++) {sl.Insert(i);}std::cout<<"\n=== Print Skip List ===\n\n";sl.Print();printf("\n=== Search Skip List ===\n\n");TIME_START;for (i = 0; i < count; i++) {int value = rand()%(count+10);sl.Search(value);}TIME_END;std::cout<<"\n=== Delete Skip List ===\n\n";char buf[256], *p = buf;for (i = 0; i < count+10; i+=2) {sprintf_s(buf, "Delete[%d]:%s\n", i, sl.Delete(i) ? "SUCCESS":"NOT FOUND");std::cout<<buf;}std::cout<<"\n\n";sl.Print();sl.Free();//或者Ctrl+F5調試getchar(); }

總結

以上是生活随笔為你收集整理的一种数据结构 跳表skiplist的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。