基礎資料結構演算法總結

2022-07-25 02:39:05 字數 1974 閱讀 4003

對本科使用的資料結構課本感情很深, 當初學的時候, 並不需要上機程式設計, 考試時只需寫出偽**即可. 而今, 實現的細節已經變得必須了, 所以, 再次拿出課本, 複習一下實現細節

資料結構和演算法

1. 堆的實現(插入, 刪除, 初始化, 以最大根為例) 

2. 快排的實現

3. 歸併排序的實現

4. 陣列實現佇列

1. 堆的實現, **

template class maxheap 

t max() const

maxheap& insert(const t &x);

maxheap& delete(t &x);

void initialize(t a, int size, int arraysize);

private:

int currentsize, maxsize;

t *heap;

};template maxheap::maxheap(int maxheapsize)

template maxheap& maxheap::insert(const t &x)

heap[i] = x;

return *this;

}template maxheap& maxheap::delete(t &x)

heap[i] = y;

return *this;

}template void maxheap::initialize(t a, int size, int arraysize)

heap[c/2] = y;

}}

2. 快排的實現

template void quicksort(t *a, int n)  

template void quicksort(t *a, int l, int r) while(t[i] < pivot);

do while(t[j] > pivot);

if(i >= j) break;

swap(t[i], t[j]);

} a[l] = a[j];

a[j] = pivot;

quicksort(t, l, j-1);

quicksort(t, j+1, r);

}

3. 歸併排序

template void mergesort(t a, int n)  

delete b;

}template void mergepass(t a, t b, int seg, int n)

if(i < n - seg) else

}template void merge(t a, t b, int l, int m, int r) else

} while(i < m)

while(j < m)

}

4. 陣列實現佇列

template class queue 

bool isempty() const

bool isfull() const

t first() const;

t last() const;

queue& add(const t &x);

queue& delete();

private:

int front;

int rear;

int maxsize;

t *queue;

};template queue::queue(int maxqueuesize)

template t queue::first() const

template t queue::last() const

templatequeue& queue::add(const t &x)

template queue& queue::delete()

資料結構與演算法總結

本教材共十一章 第一章為資料結構與演算法概述,為本書學習基礎和預備知識。資料的邏輯結構是對資料之間關係的描述,有時就把邏輯結構簡稱為資料結構。邏輯結構形式地定義為 k,r 或 d,s 其中,k是 資料元素的有限集,r是k 上的關係的有限集。邏輯結構有四種基本型別 集合結構 線性結構 樹狀結構和網路結...

資料結構排序演算法總結

常用的演算法有插入排序 氣泡排序 選擇排序 快速排序 歸併排序 希爾排序 堆排序 計數排序和基數排序。下面對著九種常見排序方法進行總結 排序方法 時間複雜度 空間複雜度 個人評價 插入排序 o n 2 o 1 選擇排序 氣泡排序 希爾排序 o n log n 快速排序 o log n 歸併排序 o ...

資料結構(五)演算法總結

最壞情況與平均情況 最壞情況時間是一種保證,那就是執行時間不會再壞了。在應用中,這是一種最重要的需求,通常,除非特別指定,我們提到的執行時間都是最壞情況的執行時間。平均執行時間是所有情況中最有意義的,因為他是期望的執行時間。一般在沒有特殊說明的情況下,都是指最壞時間複雜度。演算法空間複雜度 演算法的...