#include#includeusing namespace std;
const int maxn = 100;
//heap為堆,n為元素個數
int heap[maxn], n = 10;
//對heap陣列在[low,high]範圍進行向下調整
//其中low為欲調整結點的陣列下標,high一般為堆的最後乙個元素的陣列下標
void downadjust(int low, int high)
//如果孩子中最大的權值比欲調整結點i大
if (heap[j] > heap[i])
else
}}//建堆
void createheap()
}//刪除堆頂元素
void deletetop()
//對heap陣列在[low,high]範圍進行向上調整
//其中low一般設定為1,high表示欲調整結點的陣列下標
void upadjust(int low, int high)
else
break;//父親權值比欲調整結點i的權值大,調整結束 }}
void insert(int x)
//堆排序
void heapsort()
}int main()
heapsort();
for (int i = 1; i <= n; i++)
return 0;}/*
輸入為:
堆的一些簡單操作
僅僅是記錄一下自己寫過的堆操作的 個人覺得堆的優勢在於建立和獲取最小或者最大元的方便,有任何次序要求的演算法,堆並不合適。include include include typedef struct priorityqueue priorityqueue void printpriorityqueu...
一些時間相關操作
1.求星期公式 星期 5 a 實際天數 mod 7 2.干支計算公式 六十甲子干支序號,從1 59 0。六十甲子干支序號 23 a 實際天數 mod 60 3.二十八宿計算公式 二十八宿序號 23 a 實際天數 mod 28 4.實際天數a的計算 a b 基本天數 c 閏日天數 b 計算年 1 36...
堆的一些基本操作實現
關於建堆和對其的一些操作 include include using namespace std const int maxn 100 int heap maxn n 10 將第乙個結點儲存在陣列的一號位 函式功能 對heap陣列在low到high的範圍內向下調整 void downadjust i...