# 減小斐波那契堆上的鍵和刪除節點的操作
> 原文: [https://www.programiz.com/dsa/decrease-key-and-delete-node-from-a-fibonacci-heap](https://www.programiz.com/dsa/decrease-key-and-delete-node-from-a-fibonacci-heap)
#### 在本教程中,您將學習減小鍵和刪除節點操作的工作方式。 此外,您還將在 C,C++ ,Java 和 Python 的斐波那契堆上找到這些操作的工作示例。
在斐波那契堆中,減小鍵和刪除節點是重要的操作。 這些操作將在下面討論。
* * *
## 減小鍵
在減小鍵操作中,鍵的值被減小到較低的值。
以下函數用于減小鍵。
### 減小鍵
1. 選擇要減小的節點`x`,并將其值更改為新值`k`。
2. 如果`x`的父級`y`不為空,并且父級的鍵大于`k`的鍵,則調用`C ut(x)`和`C ascading- C ut(y)`隨后。
3. 如果`x`的鍵小于`min`的鍵,則將`x`標記為`min`。
### 剪裁
1. 從當前位置刪除`x`并將其添加到根列表中。
2. 如果標記了`x`,則將其標記為`false`。
### 級聯剪裁
1. 如果`y`的父級不為空,請執行以下步驟。
2. 如果未標記`y`,則標記`y`。
3. 否則,調用`Cut(y)`和`Cascading-Cut(parent of y)`。
* * *
## 減小鍵示例
在以下示例中可以理解上述操作。
### 示例:將 46 減小到 15。
1. 將值減小 46 到 15。
2. **剪裁部分**:由于`24 ≠ nill`和`15 < its parent`,將其剪裁并將其添加到根列表中。 **級聯剪裁部分**:標記為 24。

在根列表中添加 15 并標記為 24
### 示例:將 35 減小到 5
1. 將值減小 35 到 5。

將值 35 減小到 5
2. 剪裁部分:由于`26 ≠ nill`和`5<its parent`,將其剪裁并將其添加到根列表中。

剪裁 5 并將其添加到根列表
3. 級聯剪裁部分:由于標記為 26,因此流程進入`Cut`和`Cascading-Cut`。
`Cut(26)`:剪裁 26 并將其添加到根列表中,并將其標記為`false`。

剪裁 26 并將其添加到根列表中。 調用`Cut(24)`和`Cascading-Cut(7)`。 這些操作將導致下面的樹。

削減 24 并將其添加到根列表中
4. 從`5 < 7`開始,將 5 標記為分鐘。

將 5 標記為最小值
* * *
## 刪除節點
此過程使用[減小鍵](None)和[最小提取](https://www.programiz.com/dsa/fibonacci-heap)操作。 請按照以下步驟刪除節點。
1. 令`k`為要刪除的節點。
2. 應用減小鍵操作將`k`的值減小到可能的最低值(即-∞)。
3. 應用`extract-min`操作刪除該節點。
* * *
## Python,Java 和 C/C++ 示例
```py
# Fibonacci Heap in python
import math
class FibonacciTree:
def __init__(self, key):
self.key = key
self.children = []
self.order = 0
def add_at_end(self, t):
self.children.append(t)
self.order = self.order + 1
class FibonacciHeap:
def __init__(self):
self.trees = []
self.least = None
self.count = 0
def insert(self, key):
new_tree = FibonacciTree(key)
self.trees.append(new_tree)
if (self.least is None or key < self.least.key):
self.least = new_tree
self.count = self.count + 1
def get_min(self):
if self.least is None:
return None
return self.least.key
def extract_min(self):
smallest = self.least
if smallest is not None:
for child in smallest.children:
self.trees.append(child)
self.trees.remove(smallest)
if self.trees == []:
self.least = None
else:
self.least = self.trees[0]
self.consolidate()
self.count = self.count - 1
return smallest.key
def consolidate(self):
aux = (floor_log2(self.count) + 1) * [None]
while self.trees != []:
x = self.trees[0]
order = x.order
self.trees.remove(x)
while aux[order] is not None:
y = aux[order]
if x.key > y.key:
x, y = y, x
x.add_at_end(y)
aux[order] = None
order = order + 1
aux[order] = x
self.least = None
for k in aux:
if k is not None:
self.trees.append(k)
if (self.least is None
or k.key < self.least.key):
self.least = k
def floor_log2(x):
return math.frexp(x)[1] - 1
fheap = FibonacciHeap()
fheap.insert(11)
fheap.insert(10)
fheap.insert(39)
fheap.insert(26)
fheap.insert(24)
print('Minimum value: {}'.format(fheap.get_min()))
print('Minimum value removed: {}'.format(fheap.extract_min()))
```
```java
// Operations on Fibonacci Heap in Java
class node {
node parent;
node left;
node right;
node child;
int degree;
boolean mark;
int key;
public node() {
this.degree = 0;
this.mark = false;
this.parent = null;
this.left = this;
this.right = this;
this.child = null;
this.key = Integer.MAX_VALUE;
}
node(int x) {
this();
this.key = x;
}
void set_parent(node x) {
this.parent = x;
}
node get_parent() {
return this.parent;
}
void set_left(node x) {
this.left = x;
}
node get_left() {
return this.left;
}
void set_right(node x) {
this.right = x;
}
node get_right() {
return this.right;
}
void set_child(node x) {
this.child = x;
}
node get_child() {
return this.child;
}
void set_degree(int x) {
this.degree = x;
}
int get_degree() {
return this.degree;
}
void set_mark(boolean m) {
this.mark = m;
}
boolean get_mark() {
return this.mark;
}
void set_key(int x) {
this.key = x;
}
int get_key() {
return this.key;
}
}
public class fibHeap {
node min;
int n;
boolean trace;
node found;
public boolean get_trace() {
return trace;
}
public void set_trace(boolean t) {
this.trace = t;
}
public static fibHeap create_heap() {
return new fibHeap();
}
fibHeap() {
min = null;
n = 0;
trace = false;
}
private void insert(node x) {
if (min == null) {
min = x;
x.set_left(min);
x.set_right(min);
} else {
x.set_right(min);
x.set_left(min.get_left());
min.get_left().set_right(x);
min.set_left(x);
if (x.get_key() < min.get_key())
min = x;
}
n += 1;
}
public void insert(int key) {
insert(new node(key));
}
public void display() {
display(min);
System.out.println();
}
private void display(node c) {
System.out.print("(");
if (c == null) {
System.out.print(")");
return;
} else {
node temp = c;
do {
System.out.print(temp.get_key());
node k = temp.get_child();
display(k);
System.out.print("->");
temp = temp.get_right();
} while (temp != c);
System.out.print(")");
}
}
public static void merge_heap(fibHeap H1, fibHeap H2, fibHeap H3) {
H3.min = H1.min;
if (H1.min != null && H2.min != null) {
node t1 = H1.min.get_left();
node t2 = H2.min.get_left();
H1.min.set_left(t2);
t1.set_right(H2.min);
H2.min.set_left(t1);
t2.set_right(H1.min);
}
if (H1.min == null || (H2.min != null && H2.min.get_key() < H1.min.get_key()))
H3.min = H2.min;
H3.n = H1.n + H2.n;
}
public int find_min() {
return this.min.get_key();
}
private void display_node(node z) {
System.out.println("right: " + ((z.get_right() == null) ? "-1" : z.get_right().get_key()));
System.out.println("left: " + ((z.get_left() == null) ? "-1" : z.get_left().get_key()));
System.out.println("child: " + ((z.get_child() == null) ? "-1" : z.get_child().get_key()));
System.out.println("degree " + z.get_degree());
}
public int extract_min() {
node z = this.min;
if (z != null) {
node c = z.get_child();
node k = c, p;
if (c != null) {
do {
p = c.get_right();
insert(c);
c.set_parent(null);
c = p;
} while (c != null && c != k);
}
z.get_left().set_right(z.get_right());
z.get_right().set_left(z.get_left());
z.set_child(null);
if (z == z.get_right())
this.min = null;
else {
this.min = z.get_right();
this.consolidate();
}
this.n -= 1;
return z.get_key();
}
return Integer.MAX_VALUE;
}
public void consolidate() {
double phi = (1 + Math.sqrt(5)) / 2;
int Dofn = (int) (Math.log(this.n) / Math.log(phi));
node[] A = new node[Dofn + 1];
for (int i = 0; i <= Dofn; ++i)
A[i] = null;
node w = min;
if (w != null) {
node check = min;
do {
node x = w;
int d = x.get_degree();
while (A[d] != null) {
node y = A[d];
if (x.get_key() > y.get_key()) {
node temp = x;
x = y;
y = temp;
w = x;
}
fib_heap_link(y, x);
check = x;
A[d] = null;
d += 1;
}
A[d] = x;
w = w.get_right();
} while (w != null && w != check);
this.min = null;
for (int i = 0; i <= Dofn; ++i) {
if (A[i] != null) {
insert(A[i]);
}
}
}
}
private void fib_heap_link(node y, node x) {
y.get_left().set_right(y.get_right());
y.get_right().set_left(y.get_left());
node p = x.get_child();
if (p == null) {
y.set_right(y);
y.set_left(y);
} else {
y.set_right(p);
y.set_left(p.get_left());
p.get_left().set_right(y);
p.set_left(y);
}
y.set_parent(x);
x.set_child(y);
x.set_degree(x.get_degree() + 1);
y.set_mark(false);
}
private void find(int key, node c) {
if (found != null || c == null)
return;
else {
node temp = c;
do {
if (key == temp.get_key())
found = temp;
else {
node k = temp.get_child();
find(key, k);
temp = temp.get_right();
}
} while (temp != c && found == null);
}
}
public node find(int k) {
found = null;
find(k, this.min);
return found;
}
public void decrease_key(int key, int nval) {
node x = find(key);
decrease_key(x, nval);
}
private void decrease_key(node x, int k) {
if (k > x.get_key())
return;
x.set_key(k);
node y = x.get_parent();
if (y != null && x.get_key() < y.get_key()) {
cut(x, y);
cascading_cut(y);
}
if (x.get_key() < min.get_key())
min = x;
}
private void cut(node x, node y) {
x.get_right().set_left(x.get_left());
x.get_left().set_right(x.get_right());
y.set_degree(y.get_degree() - 1);
x.set_right(null);
x.set_left(null);
insert(x);
x.set_parent(null);
x.set_mark(false);
}
private void cascading_cut(node y) {
node z = y.get_parent();
if (z != null) {
if (y.get_mark() == false)
y.set_mark(true);
else {
cut(y, z);
cascading_cut(z);
}
}
}
public void delete(node x) {
decrease_key(x, Integer.MIN_VALUE);
int p = extract_min();
}
public static void main(String[] args) {
fibHeap obj = create_heap();
obj.insert(7);
obj.insert(26);
obj.insert(30);
obj.insert(39);
obj.insert(10);
obj.display();
System.out.println(obj.extract_min());
obj.display();
System.out.println(obj.extract_min());
obj.display();
System.out.println(obj.extract_min());
obj.display();
System.out.println(obj.extract_min());
obj.display();
System.out.println(obj.extract_min());
obj.display();
}
}
```
```c
// Operations on a Fibonacci heap in C
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
typedef struct _NODE
{
int key;
int degree;
struct _NODE *left_sibling;
struct _NODE *right_sibling;
struct _NODE *parent;
struct _NODE *child;
bool mark;
bool visited;
} NODE;
typedef struct fibanocci_heap
{
int n;
NODE *min;
int phi;
int degree;
} FIB_HEAP;
FIB_HEAP *make_fib_heap();
void insertion(FIB_HEAP *H, NODE *new, int val);
NODE *extract_min(FIB_HEAP *H);
void consolidate(FIB_HEAP *H);
void fib_heap_link(FIB_HEAP *H, NODE *y, NODE *x);
NODE *find_min_node(FIB_HEAP *H);
void decrease_key(FIB_HEAP *H, NODE *node, int key);
void cut(FIB_HEAP *H, NODE *node_to_be_decrease, NODE *parent_node);
void cascading_cut(FIB_HEAP *H, NODE *parent_node);
void Delete_Node(FIB_HEAP *H, int dec_key);
FIB_HEAP *make_fib_heap()
{
FIB_HEAP *H;
H = (FIB_HEAP *)malloc(sizeof(FIB_HEAP));
H->n = 0;
H->min = NULL;
H->phi = 0;
H->degree = 0;
return H;
}
void new_print_heap(NODE *n)
{
NODE *x;
for (x = n;; x = x->right_sibling)
{
if (x->child == NULL)
{
printf("node with no child (%d) \n", x->key);
}
else
{
printf("NODE(%d) with child (%d)\n", x->key, x->child->key);
new_print_heap(x->child);
}
if (x->right_sibling == n)
{
break;
}
}
}
void insertion(FIB_HEAP *H, NODE *new, int val)
{
new = (NODE *)malloc(sizeof(NODE));
new->key = val;
new->degree = 0;
new->mark = false;
new->parent = NULL;
new->child = NULL;
new->visited = false;
new->left_sibling = new;
new->right_sibling = new;
if (H->min == NULL)
{
H->min = new;
}
else
{
H->min->left_sibling->right_sibling = new;
new->right_sibling = H->min;
new->left_sibling = H->min->left_sibling;
H->min->left_sibling = new;
if (new->key < H->min->key)
{
H->min = new;
}
}
(H->n)++;
}
NODE *find_min_node(FIB_HEAP *H)
{
if (H == NULL)
{
printf(" \n Fibonacci heap not yet created \n");
return NULL;
}
else
return H->min;
}
FIB_HEAP *unionHeap(FIB_HEAP *H1, FIB_HEAP *H2)
{
FIB_HEAP *Hnew;
Hnew = make_fib_heap();
Hnew->min = H1->min;
NODE *temp1, *temp2;
temp1 = Hnew->min->right_sibling;
temp2 = H2->min->left_sibling;
Hnew->min->right_sibling->left_sibling = H2->min->left_sibling;
Hnew->min->right_sibling = H2->min;
H2->min->left_sibling = Hnew->min;
temp2->right_sibling = temp1;
if ((H1->min == NULL) || (H2->min != NULL && H2->min->key < H1->min->key))
Hnew->min = H2->min;
Hnew->n = H1->n + H2->n;
return Hnew;
}
int cal_degree(int n)
{
int count = 0;
while (n > 0)
{
n = n / 2;
count++;
}
return count;
}
void consolidate(FIB_HEAP *H)
{
int degree, i, d;
degree = cal_degree(H->n);
NODE *A[degree], *x, *y, *z;
for (i = 0; i <= degree; i++)
{
A[i] = NULL;
}
x = H->min;
do
{
d = x->degree;
while (A[d] != NULL)
{
y = A[d];
if (x->key > y->key)
{
NODE *exchange_help;
exchange_help = x;
x = y;
y = exchange_help;
}
if (y == H->min)
H->min = x;
fib_heap_link(H, y, x);
if (y->right_sibling == x)
H->min = x;
A[d] = NULL;
d++;
}
A[d] = x;
x = x->right_sibling;
} while (x != H->min);
H->min = NULL;
for (i = 0; i < degree; i++)
{
if (A[i] != NULL)
{
A[i]->left_sibling = A[i];
A[i]->right_sibling = A[i];
if (H->min == NULL)
{
H->min = A[i];
}
else
{
H->min->left_sibling->right_sibling = A[i];
A[i]->right_sibling = H->min;
A[i]->left_sibling = H->min->left_sibling;
H->min->left_sibling = A[i];
if (A[i]->key < H->min->key)
{
H->min = A[i];
}
}
if (H->min == NULL)
{
H->min = A[i];
}
else if (A[i]->key < H->min->key)
{
H->min = A[i];
}
}
}
}
void fib_heap_link(FIB_HEAP *H, NODE *y, NODE *x)
{
y->right_sibling->left_sibling = y->left_sibling;
y->left_sibling->right_sibling = y->right_sibling;
if (x->right_sibling == x)
H->min = x;
y->left_sibling = y;
y->right_sibling = y;
y->parent = x;
if (x->child == NULL)
{
x->child = y;
}
y->right_sibling = x->child;
y->left_sibling = x->child->left_sibling;
x->child->left_sibling->right_sibling = y;
x->child->left_sibling = y;
if ((y->key) < (x->child->key))
x->child = y;
(x->degree)++;
}
NODE *extract_min(FIB_HEAP *H)
{
if (H->min == NULL)
printf("\n The heap is empty");
else
{
NODE *temp = H->min;
NODE *pntr;
pntr = temp;
NODE *x = NULL;
if (temp->child != NULL)
{
x = temp->child;
do
{
pntr = x->right_sibling;
(H->min->left_sibling)->right_sibling = x;
x->right_sibling = H->min;
x->left_sibling = H->min->left_sibling;
H->min->left_sibling = x;
if (x->key < H->min->key)
H->min = x;
x->parent = NULL;
x = pntr;
} while (pntr != temp->child);
}
(temp->left_sibling)->right_sibling = temp->right_sibling;
(temp->right_sibling)->left_sibling = temp->left_sibling;
H->min = temp->right_sibling;
if (temp == temp->right_sibling && temp->child == NULL)
H->min = NULL;
else
{
H->min = temp->right_sibling;
consolidate(H);
}
H->n = H->n - 1;
return temp;
}
return H->min;
}
void cut(FIB_HEAP *H, NODE *node_to_be_decrease, NODE *parent_node)
{
NODE *temp_parent_check;
if (node_to_be_decrease == node_to_be_decrease->right_sibling)
parent_node->child = NULL;
node_to_be_decrease->left_sibling->right_sibling = node_to_be_decrease->right_sibling;
node_to_be_decrease->right_sibling->left_sibling = node_to_be_decrease->left_sibling;
if (node_to_be_decrease == parent_node->child)
parent_node->child = node_to_be_decrease->right_sibling;
(parent_node->degree)--;
node_to_be_decrease->left_sibling = node_to_be_decrease;
node_to_be_decrease->right_sibling = node_to_be_decrease;
H->min->left_sibling->right_sibling = node_to_be_decrease;
node_to_be_decrease->right_sibling = H->min;
node_to_be_decrease->left_sibling = H->min->left_sibling;
H->min->left_sibling = node_to_be_decrease;
node_to_be_decrease->parent = NULL;
node_to_be_decrease->mark = false;
}
void cascading_cut(FIB_HEAP *H, NODE *parent_node)
{
NODE *aux;
aux = parent_node->parent;
if (aux != NULL)
{
if (parent_node->mark == false)
{
parent_node->mark = true;
}
else
{
cut(H, parent_node, aux);
cascading_cut(H, aux);
}
}
}
void decrease_key(FIB_HEAP *H, NODE *node_to_be_decrease, int new_key)
{
NODE *parent_node;
if (H == NULL)
{
printf("\n FIbonacci heap not created ");
return;
}
if (node_to_be_decrease == NULL)
{
printf("Node is not in the heap");
}
else
{
if (node_to_be_decrease->key < new_key)
{
printf("\n Invalid new key for decrease key operation \n ");
}
else
{
node_to_be_decrease->key = new_key;
parent_node = node_to_be_decrease->parent;
if ((parent_node != NULL) && (node_to_be_decrease->key < parent_node->key))
{
printf("\n cut called");
cut(H, node_to_be_decrease, parent_node);
printf("\n cascading cut called");
cascading_cut(H, parent_node);
}
if (node_to_be_decrease->key < H->min->key)
{
H->min = node_to_be_decrease;
}
}
}
}
void *find_node(FIB_HEAP *H, NODE *n, int key, int new_key)
{
NODE *find_use = n;
NODE *f = NULL;
find_use->visited = true;
if (find_use->key == key)
{
find_use->visited = false;
f = find_use;
decrease_key(H, f, new_key);
}
if (find_use->child != NULL)
{
find_node(H, find_use->child, key, new_key);
}
if ((find_use->right_sibling->visited != true))
{
find_node(H, find_use->right_sibling, key, new_key);
}
find_use->visited = false;
}
FIB_HEAP *insertion_procedure()
{
FIB_HEAP *temp;
int no_of_nodes, ele, i;
NODE *new_node;
temp = (FIB_HEAP *)malloc(sizeof(FIB_HEAP));
temp = NULL;
if (temp == NULL)
{
temp = make_fib_heap();
}
printf(" \n enter number of nodes to be insert = ");
scanf("%d", &no_of_nodes);
for (i = 1; i <= no_of_nodes; i++)
{
printf("\n node %d and its key value = ", i);
scanf("%d", &ele);
insertion(temp, new_node, ele);
}
return temp;
}
void Delete_Node(FIB_HEAP *H, int dec_key)
{
NODE *p = NULL;
find_node(H, H->min, dec_key, -5000);
p = extract_min(H);
if (p != NULL)
printf("\n Node deleted");
else
printf("\n Node not deleted:some error");
}
int main(int argc, char **argv)
{
NODE *new_node, *min_node, *extracted_min, *node_to_be_decrease, *find_use;
FIB_HEAP *heap, *h1, *h2;
int operation_no, new_key, dec_key, ele, i, no_of_nodes;
heap = (FIB_HEAP *)malloc(sizeof(FIB_HEAP));
heap = NULL;
while (1)
{
printf(" \n choose below operations \n 1\. Create Fibonacci heap \n 2\. Insert nodes into fibonacci heap \n 3\. Find min \n 4\. Union \n 5\. Extract min \n 6\. Decrease key \n 7.Delete node \n 8\. print heap \n 9\. exit \n enter operation_no = ");
scanf("%d", &operation_no);
switch (operation_no)
{
case 1:
heap = make_fib_heap();
break;
case 2:
if (heap == NULL)
{
heap = make_fib_heap();
}
printf(" enter number of nodes to be insert = ");
scanf("%d", &no_of_nodes);
for (i = 1; i <= no_of_nodes; i++)
{
printf("\n node %d and its key value = ", i);
scanf("%d", &ele);
insertion(heap, new_node, ele);
}
break;
case 3:
min_node = find_min_node(heap);
if (min_node == NULL)
printf("No minimum value");
else
printf("\n min value = %d", min_node->key);
break;
case 4:
if (heap == NULL)
{
printf("\n no FIbonacci heap is created please create fibonacci heap \n ");
break;
}
h1 = insertion_procedure();
heap = unionHeap(heap, h1);
printf("Unified Heap:\n");
new_print_heap(heap->min);
break;
case 5:
if (heap == NULL)
printf("Fibonacci heap is empty");
else
{
extracted_min = extract_min(heap);
printf("\n min value = %d", extracted_min->key);
printf("\n Updated heap: \n");
new_print_heap(heap->min);
}
break;
case 6:
if (heap == NULL)
printf("Fibonacci heap is empty");
else
{
printf(" \n node to be decreased = ");
scanf("%d", &dec_key);
printf(" \n enter the new key = ");
scanf("%d", &new_key);
find_use = heap->min;
find_node(heap, find_use, dec_key, new_key);
printf("\n Key decreased- Corresponding heap:\n");
new_print_heap(heap->min);
}
break;
case 7:
if (heap == NULL)
printf("Fibonacci heap is empty");
else
{
printf(" \n Enter node key to be deleted = ");
scanf("%d", &dec_key);
Delete_Node(heap, dec_key);
printf("\n Node Deleted- Corresponding heap:\n");
new_print_heap(heap->min);
break;
}
case 8:
new_print_heap(heap->min);
break;
case 9:
free(new_node);
free(heap);
exit(0);
default:
printf("Invalid choice ");
}
}
}
```
```cpp
// Operations on a Fibonacci heap in C++
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
struct node
{
int n;
int degree;
node *parent;
node *child;
node *left;
node *right;
char mark;
char C;
};
class FibonacciHeap
{
private:
int nH;
node *H;
public:
node *InitializeHeap();
int Fibonnaci_link(node *, node *, node *);
node *Create_node(int);
node *Insert(node *, node *);
node *Union(node *, node *);
node *Extract_Min(node *);
int Consolidate(node *);
int Display(node *);
node *Find(node *, int);
int Decrease_key(node *, int, int);
int Delete_key(node *, int);
int Cut(node *, node *, node *);
int Cascase_cut(node *, node *);
FibonacciHeap() { H = InitializeHeap(); }
};
node *FibonacciHeap::InitializeHeap()
{
node *np;
np = NULL;
return np;
}
node *FibonacciHeap::Create_node(int value)
{
node *x = new node;
x->n = value;
return x;
}
node *FibonacciHeap::Insert(node *H, node *x)
{
x->degree = 0;
x->parent = NULL;
x->child = NULL;
x->left = x;
x->right = x;
x->mark = 'F';
x->C = 'N';
if (H != NULL)
{
(H->left)->right = x;
x->right = H;
x->left = H->left;
H->left = x;
if (x->n < H->n)
H = x;
}
else
{
H = x;
}
nH = nH + 1;
return H;
}
int FibonacciHeap::Fibonnaci_link(node *H1, node *y, node *z)
{
(y->left)->right = y->right;
(y->right)->left = y->left;
if (z->right == z)
H1 = z;
y->left = y;
y->right = y;
y->parent = z;
if (z->child == NULL)
z->child = y;
y->right = z->child;
y->left = (z->child)->left;
((z->child)->left)->right = y;
(z->child)->left = y;
if (y->n < (z->child)->n)
z->child = y;
z->degree++;
}
node *FibonacciHeap::Union(node *H1, node *H2)
{
node *np;
node *H = InitializeHeap();
H = H1;
(H->left)->right = H2;
(H2->left)->right = H;
np = H->left;
H->left = H2->left;
H2->left = np;
return H;
}
int FibonacciHeap::Display(node *H)
{
node *p = H;
if (p == NULL)
{
cout << "The Heap is Empty" << endl;
return 0;
}
cout << "The root nodes of Heap are: " << endl;
do
{
cout << p->n;
p = p->right;
if (p != H)
{
cout << "-->";
}
} while (p != H && p->right != NULL);
cout << endl;
}
node *FibonacciHeap::Extract_Min(node *H1)
{
node *p;
node *ptr;
node *z = H1;
p = z;
ptr = z;
if (z == NULL)
return z;
node *x;
node *np;
x = NULL;
if (z->child != NULL)
x = z->child;
if (x != NULL)
{
ptr = x;
do
{
np = x->right;
(H1->left)->right = x;
x->right = H1;
x->left = H1->left;
H1->left = x;
if (x->n < H1->n)
H1 = x;
x->parent = NULL;
x = np;
} while (np != ptr);
}
(z->left)->right = z->right;
(z->right)->left = z->left;
H1 = z->right;
if (z == z->right && z->child == NULL)
H = NULL;
else
{
H1 = z->right;
Consolidate(H1);
}
nH = nH - 1;
return p;
}
int FibonacciHeap::Consolidate(node *H1)
{
int d, i;
float f = (log(nH)) / (log(2));
int D = f;
node *A[D];
for (i = 0; i <= D; i++)
A[i] = NULL;
node *x = H1;
node *y;
node *np;
node *pt = x;
do
{
pt = pt->right;
d = x->degree;
while (A[d] != NULL)
{
y = A[d];
if (x->n > y->n)
{
np = x;
x = y;
y = np;
}
if (y == H1)
H1 = x;
Fibonnaci_link(H1, y, x);
if (x->right == x)
H1 = x;
A[d] = NULL;
d = d + 1;
}
A[d] = x;
x = x->right;
}
while (x != H1);
H = NULL;
for (int j = 0; j <= D; j++)
{
if (A[j] != NULL)
{
A[j]->left = A[j];
A[j]->right = A[j];
if (H != NULL)
{
(H->left)->right = A[j];
A[j]->right = H;
A[j]->left = H->left;
H->left = A[j];
if (A[j]->n < H->n)
H = A[j];
}
else
{
H = A[j];
}
if (H == NULL)
H = A[j];
else if (A[j]->n < H->n)
H = A[j];
}
}
}
int FibonacciHeap::Decrease_key(node *H1, int x, int k)
{
node *y;
if (H1 == NULL)
{
cout << "The Heap is Empty" << endl;
return 0;
}
node *ptr = Find(H1, x);
if (ptr == NULL)
{
cout << "Node not found in the Heap" << endl;
return 1;
}
if (ptr->n < k)
{
cout << "Entered key greater than current key" << endl;
return 0;
}
ptr->n = k;
y = ptr->parent;
if (y != NULL && ptr->n < y->n)
{
Cut(H1, ptr, y);
Cascase_cut(H1, y);
}
if (ptr->n < H->n)
H = ptr;
return 0;
}
int FibonacciHeap::Cut(node *H1, node *x, node *y)
{
if (x == x->right)
y->child = NULL;
(x->left)->right = x->right;
(x->right)->left = x->left;
if (x == y->child)
y->child = x->right;
y->degree = y->degree - 1;
x->right = x;
x->left = x;
(H1->left)->right = x;
x->right = H1;
x->left = H1->left;
H1->left = x;
x->parent = NULL;
x->mark = 'F';
}
int FibonacciHeap::Cascase_cut(node *H1, node *y)
{
node *z = y->parent;
if (z != NULL)
{
if (y->mark == 'F')
{
y->mark = 'T';
}
else
{
Cut(H1, y, z);
Cascase_cut(H1, z);
}
}
}
node *FibonacciHeap::Find(node *H, int k)
{
node *x = H;
x->C = 'Y';
node *p = NULL;
if (x->n == k)
{
p = x;
x->C = 'N';
return p;
}
if (p == NULL)
{
if (x->child != NULL)
p = Find(x->child, k);
if ((x->right)->C != 'Y')
p = Find(x->right, k);
}
x->C = 'N';
return p;
}
int FibonacciHeap::Delete_key(node *H1, int k)
{
node *np = NULL;
int t;
t = Decrease_key(H1, k, -5000);
if (!t)
np = Extract_Min(H);
if (np != NULL)
cout << "Key Deleted" << endl;
else
cout << "Key not Deleted" << endl;
return 0;
}
int main()
{
int n, m, l;
FibonacciHeap fh;
node *p;
node *H;
H = fh.InitializeHeap();
p = fh.Create_node(7);
H = fh.Insert(H, p);
p = fh.Create_node(17);
H = fh.Insert(H, p);
p = fh.Create_node(26);
H = fh.Insert(H, p);
p = fh.Create_node(1);
H = fh.Insert(H, p);
fh.Display(H);
p = fh.Extract_Min(H);
if (p != NULL)
cout << "The node with minimum key: " << p->n << endl;
else
cout << "Heap is empty" << endl;
m = 26;
l = 16;
fh.Decrease_key(H, m, l);
m = 16;
fh.Delete_key(H, m);
}
```
* * *
## 復雜度
| | |
| --- | --- |
| 減小鍵 | `O(1)` |
| 刪除節點 | `O(log n)` |
- Programiz C 語言教程
- C 簡介
- C 關鍵字和標識符
- C 變量,常量和字面值
- C 數據類型
- C 輸入輸出(I/O)
- C 編程運算符
- C 簡單示例
- C 流程控制
- C if...else語句
- C for循環
- C while和do...while循環
- C break和continue
- C switch語句
- C goto聲明
- C 控制流程示例
- C 函數
- C 函數
- C 用戶定義的函數
- C 編程中用戶定義函數的類型
- C 遞歸
- C 存儲類
- C 函數示例
- C 數組
- C 數組
- C 多維數組
- 將數組傳遞給 C 中的函數
- C 編程指針
- C 指針
- 數組和指針之間的關系
- C 按引用調用:使用指針
- C 動態內存分配
- C 數組和指針示例
- C 字符串
- C 編程字符串
- 使用庫函數進行 C 編程中的字符串操作
- C 編程中的字符串示例
- 結構與聯合
- 結構
- 結構和指針
- C 結構與函數
- C 聯合
- C 結構示例
- C 文件
- C 文件處理
- C 文件示例
- 其他主題
- 枚舉
- C 預處理器和宏
- C 標準庫函數
- C 示例
- C 程序:打印金字塔和圖案
- C 程序:檢查數字是否為質數
- C 程序:檢查數字是否為回文
- C 程序:HelloWorld
- C 程序:打印整數(由用戶輸入)
- C 程序:相加兩個整數
- C 程序:將兩個浮點數相乘
- C 程序:查找字符的 ASCII 值
- C 程序:商和余數
- C 程序:查找int,float,double和char的大小
- C 程序:long關鍵字演示
- C 程序:交換兩個數字
- C 程序:檢查數字是偶數還是奇數
- C 程序:檢查字符是元音還是輔音
- C 程序:查找三個數字中最大的數字
- C 程序:查找二次方程的根
- C 程序:檢查閏年
- C 程序:檢查數字是正數還是負數
- C 程序:檢查字符是否為字母
- C 程序:計算自然數之和
- C 程序:查找數字階乘
- C 程序:生成乘法表
- C 程序:顯示斐波那契數列
- C 程序:查找兩個數字的 GCD
- C 程序:查找兩個數字的 LCM
- C 程序:使用循環從 A 到 Z 顯示字符
- C 程序:計算整數中的位數
- C 程序:反轉數字
- C 程序:計算數字的冪
- C 程序:顯示兩個間隔之間的質數
- C 程序:檢查阿姆斯特朗數
- C 程序:在兩個間隔之間顯示阿姆斯特朗數
- C 程序:顯示數字因數
- C 程序:使用switch...case制作一個簡單的計算器
- C 程序:使用函數顯示區間內的質數
- C 程序:使用用戶定義的函數檢查質數或阿姆斯特朗數
- C 程序:檢查一個數字是否可以表示為兩個質數之和
- C 程序:使用遞歸查找自然數之和
- C 程序:使用遞歸查找數字的階乘
- C 程序:使用遞歸查找 GCD
- C 程序:將二進制數轉換為十進制,反之亦然
- C 程序:將八進制數轉換為十進制,反之亦然
- C 程序:將二進制數轉換為八進制,反之亦然
- C 程序:使用遞歸來反轉句子
- C 程序:使用遞歸計算冪
- C 程序:使用數組計算平均值
- C 程序:查找數組中的最大元素
- C 程序:計算標準差
- C 程序:使用多維數組相加兩個矩陣
- C 程序:使用多維數組將兩個矩陣相乘
- C 程序:查找矩陣的轉置
- C 程序:通過將矩陣傳遞給函數來將兩個矩陣相乘
- C 程序:使用指針訪問數組元素
- C 程序:使用按引用調用以循環順序交換數字
- C 程序:使用動態內存分配查找最大數字
- C 程序:查找字符串中字符的頻率
- C 程序:計算元音,輔音等的數量
- C 程序:刪除字符串中除字母之外的所有字符
- C 程序:查找字符串的長度
- C 程序:連接兩個字符串
- C 程序:不使用strcpy()復制字符串
- C 程序:按字典順序(字典順序)對元素進行排序
- C 程序:使用程序存儲學生信息
- C 程序:使用結構相加兩個距離(以英寸-英尺系統為單位)
- C 程序:通過將結構傳遞給函數來相加兩個復數
- C 程序:計算兩個時間段之間的差異
- C 程序:使用結構存儲學生信息
- C 程序:在結構中動態存儲數據
- C 程序:將句子寫入文件
- C 程序:從文件中讀取一行并顯示它
- C 程序:顯示自己的源代碼作為輸出
- Programiz C++ 教程
- C++ 簡介
- C++ 變量,文字和常量
- C++ 數據類型
- C++ 基本輸入/輸出
- C++ 類型轉換
- C++ 運算符
- C++ 注釋
- C++ 流控制
- C++ if,if...else和嵌套if...else
- C++ for循環
- C++ while和do...while循環
- C++ break語句
- C++ switch..case語句
- C++ goto語句
- C++ 函數
- C++ 函數
- C++ 中用戶定義函數的類型
- C++ 函數重載
- C++ 編程默認參數(參數)
- C++ 存儲類
- C++ 遞歸
- C++ 通過引用返回
- C++ 數組和字符串
- C++ 數組
- C++ 多維數組
- 在 C++ 編程中將數組傳遞給函數
- C++ 字符串
- C++ 結構
- C++ 結構
- C++ 結構與功能
- C++ 結構指針
- C++ 枚舉
- C++ 對象和類
- C++ 類和對象
- C++ 構造器
- 如何通過 C++ 中的函數傳遞和返回對象?
- C++ 運算符重載
- C++ 指針
- C++ 指針
- C++ 指針和數組
- 通過引用進行 C++ 調用:使用指針[包含示例]
- C++ 內存管理:new和delete
- C++ 繼承
- C++ 繼承
- C++ 編程中的公共,受保護和私有繼承
- C++ 函數覆蓋
- C++ 多重,多層和層次繼承
- C++ 友元函數和友元類
- C++ 虛函數
- C++ 模板
- C++ 示例
- C++ 程序:HelloWorld
- C++ 程序:檢查數字是否為質數
- C++ 程序:創建金字塔和圖案
- C++ 程序:加兩個數字
- C++ 程序:打印用戶輸入的數字
- C++ 程序:查找商數和余數
- C++ 程序:在系統中查找int,float,double和char的大小
- C++ 程序:交換兩個數字
- C++ 程序:檢查數字是偶數還是奇數
- C++ 程序:檢查字符是元音還是輔音
- C++ 程序:查找三個數字中最大的數字
- C++ 程序:查找二次方程式的所有根
- C++ 程序:計算自然數之和
- C++ 程序:檢查閏年
- C++ 程序:查找階乘
- C++ 程序:生成乘法表
- C++ 程序:顯示斐波那契數列
- C++ 程序:查找 GCD
- C++ 程序:查找 LCM
- C++ 程序:反轉數字
- C++ 程序:計算數字的冪
- C++ 程序:遞增++和遞減--運算符重載
- C++ 程序:使用運算符重載減去復數
- C++ 程序:查找字符的 ASCII 值
- C++ 程序:將兩個數相乘
- C++ 程序:檢查數字是否為回文
- C++ 程序:顯示兩個間隔之間的質數
- C++ 程序:檢查阿姆斯特朗數
- C++ 程序:顯示兩個間隔之間的阿姆斯特朗數
- C++ 程序:顯示數字的因數
- C++ 程序:使用switch...case的簡單的加減乘除計算器
- C++ 程序:使用函數顯示兩個時間間隔之間的質數
- C++ 程序:通過創建函數來檢查質數
- C++ 程序:檢查數字是否可以表示為兩個質數之和
- C++ 程序:使用遞歸查找自然數之和
- C++ 程序:使用遞歸計算數字的階乘
- C++ 程序:使用遞歸查找 GCD
- C++ 程序:將二進制數轉換為十進制,反之亦然
- C++ 程序:將八進制數轉換為十進制,反之亦然
- C++ 程序:將二進制數轉換為八進制,反之亦然
- C++ 程序:使用遞歸來反轉句子
- C++ 程序:使用遞歸計算冪
- C++ 程序:使用數組計算數字平均值
- C++ 程序:查找數組的最大元素
- C++ 程序:計算標準差
- C++ 程序:使用多維數組相加兩個矩陣
- C++ 程序:使用多維數組將兩個矩陣相乘
- C++ 程序:查找矩陣的轉置
- C++ 程序:通過將矩陣傳遞給函數將兩個矩陣相乘
- C++ 程序:使用指針訪問數組元素
- C++ 程序:使用引用調用以循環順序交換數字
- C++ 程序:查找字符串中字符的頻率
- C++ 程序:查找字符串中元音,輔音,數字和空白的數量
- C++ 程序:刪除字符串中除字母之外的所有字符
- C++ 程序:查找字符串的長度
- C++ 程序:連接兩個字符串
- C++ 程序:復制字符串
- C++ 程序:按字典順序(字典順序)對元素進行排序
- C++ 程序:在結構中存儲學生的信息
- C++ 程序:使用結構相加兩個距離(以英寸-英尺為單位)
- C++ 程序:通過將結構傳遞給函數來添加復數
- C++ 程序:計算兩個時間段之間的差異
- C++ 程序:使用結構存儲和顯示信息
- Programiz C# 教程
- 簡介
- C# Hello World - 您的第一個 C# 程序
- C# 關鍵字和標識符
- C# 變量和(原始)數據類型
- C# 運算符
- C# 基本輸入和輸出
- C# 表達式,語句和塊(帶有示例)
- C# 注釋
- 流程控制
- C# if,if...else,if...else if和嵌套if語句
- C# for循環
- C# while和do...while循環
- C# foreach循環
- C# switch語句
- C# 三元(?:)運算符
- 其他話題
- C# 按位和移位運算符
- C# 預處理程序指令
- C# 編程中的命名空間
- C# 部分類和部分方法
- Programiz 數據結構和算法教程
- DSA 簡介
- 什么是算法?
- 為什么要學習數據結構和算法?
- 漸近分析
- 主定理
- 分治算法
- 數據結構(一)
- 棧
- 隊列
- 隊列類型
- 循環隊列
- 優先隊列
- 雙端隊列
- 數據結構(二)
- 鏈表
- 鏈表操作:遍歷,插入和刪除
- 鏈表的類型 - 單鏈,雙鏈和循環鏈
- 哈希表
- 堆數據結構
- 斐波那契堆
- 減小斐波那契堆上的鍵和刪除節點的操作
- 基于樹的 DSA(I)
- 樹數據結構
- 樹遍歷 - 中序,前序和后序
- 滿二叉樹
- 滿二叉樹
- 完美二叉樹
- 完全二叉樹
- 平衡二叉樹
- 二叉搜索樹(BST)
- AVL 樹
- 基于樹的 DSA(II)
- B 樹
- 插入 B 樹
- 從 B 樹刪除
- B+ 樹
- 在 B+ 樹上插入
- 從 B+ 樹中刪除
- 紅黑樹
- 插入紅黑樹
- 從紅黑樹中刪除
- 基于圖的 DSA
- 圖數據結構
- 生成樹和最小生成樹
- 強連通的組件
- 鄰接矩陣
- 鄰接表
- DFS 算法
- BFS 算法
- Bellman Ford 算法
- 排序和搜索算法
- 冒泡排序算法
- 選擇排序算法
- 插入排序算法
- 歸并排序算法
- 快速排序算法
- 計數排序算法
- 基數排序算法
- 桶排序算法
- 堆排序算法
- Shell 排序算法
- 線性搜索
- 二分搜索
- 貪婪算法
- 貪婪算法
- Ford-Fulkerson 算法
- Dijkstra 算法
- Kruskal 算法
- Prim 算法
- 霍夫曼編碼
- 動態規劃
- 動態規劃
- Floyd-Warshall 算法
- 最長公共子序列
- 其他算法
- 回溯算法
- Rabin-Karp 算法
- Programiz Java 教程
- Java 簡介
- Java HelloWorld 程序
- Java JDK,JRE 和 JVM
- Java 變量和(原始)數據類型
- Java 運算符
- Java 基本輸入和輸出
- Java 表達式,語句和塊
- Java 注釋
- Java 流程控制
- Java if,if...else語句
- Java switch語句
- Java for循環
- Java for-each循環(增強循環)
- Java while和do...while循環
- Java Break語句
- Java continue語句
- Java 數組
- Java 數組
- Java 多維數組
- Java 復制數組
- Java OOP(I)
- Java 類和對象
- Java 方法
- Java 構造器
- Java 字符串
- Java 訪問修飾符
- Java this關鍵字
- Java final關鍵字
- Java 遞歸
- Java instanceof
- Java OOP(II)
- Java 繼承
- Java 方法覆蓋
- Java super
- Java 抽象類和抽象方法
- Java 接口
- Java 多態
- Java 封裝
- Java OOP(III)
- Java 嵌套和內部類
- Java 靜態嵌套類
- Java 匿名類
- Java 單例
- Java 枚舉
- Java 枚舉構造器
- Java 枚舉字符串
- Java 反射
- Java 異常處理
- Java 異常
- Java 異常處理
- Java throw
- Java 捕獲多個異常
- Java try-with-resources
- Java 注解
- Java 注解類型
- Java 日志
- Java 斷言
- Java 列表
- Java 集合框架
- Java Collection接口
- Java List接口
- Java ArrayList類
- Java Vector
- Java Stack類
- Java 隊列
- Java Queue接口
- Java PriorityQueue
- Java Deque接口
- Java LinkedList
- Java ArrayDeque
- Java BlockingQueue
- Java ArrayBlockingQueue
- Java LinkedBlockingQueue
- Java 映射
- Java Map接口
- Java HashMap
- Java LinkedHashMap
- Java WeakHashMap
- Java EnumMap
- Java SortedMap接口
- Java NavigableMap接口
- Java TreeMap
- Java ConcurrentMap接口
- Java ConcurrentHashMap
- Java 集
- Java Set接口
- Java HashSet類
- Java EnumSet
- Java LinkedHashSet
- Java SortedSet接口
- Java NavigableSet接口
- Java TreeSet
- Java 算法
- Java Iterator接口
- Java ListIterator接口
- Java I/O 流
- Java I/O 流
- Java InputStream類
- Java OutputStream類
- Java FileInputStream類
- Java FileOutputStream類
- Java ByteArrayInputStream類
- Java ByteArrayOutputStream類
- Java ObjectInputStream類
- Java ObjectOutputStream類
- Java BufferedInputStream類
- Java BufferedOutputStream類
- Java PrintStream類
- Java 讀取器/寫入器
- Java Reader類
- Java Writer類
- Java InputStreamReader類
- Java OutputStreamWriter類
- Java FileReader類
- Java FileWriter類
- Java BufferedReader類
- Java BufferedWriter類
- Java StringReader類
- Java StringWriter類
- Java PrintWriter類
- 其他主題
- Java Scanner類
- Java 類型轉換
- Java 自動裝箱和拆箱
- Java Lambda 表達式
- Java 泛型
- Java File類
- Java 包裝器類
- Java 命令行參數
- Java 實例
- Java 程序:檢查數字是否為質數
- Java 程序:顯示斐波那契數列
- Java 程序:創建金字塔和圖案
- Java 程序:反轉數字
- Java 程序:打印整數(由用戶輸入)
- Java 程序:相加兩個整數
- Java 程序:將兩個浮點數相乘
- Java 程序:查找字符的 ASCII 值
- Java 程序:計算商數和余數
- Java 程序:交換兩個數字
- Java 程序:檢查數字是偶數還是奇數
- Java 程序:檢查字母是元音還是輔音
- Java 程序:在三個數字中找到最大值
- Java 程序:查找二次方程式的所有根
- Java 程序:檢查閏年
- Java 程序:檢查數字是正數還是負數
- Java 程序:檢查字符是否為字母
- Java 程序:計算自然數之和
- Java 程序:查找數字的階乘
- Java 程序:生成乘法表
- Java 程序:顯示斐波那契數列
- Java 程序:查找兩個數字的 GCD
- Java 程序:查找兩個數字的 LCM
- Java 程序:使用循環從 A 到 Z 顯示字符
- Java 程序:計算整數的位數
- Java 程序:計算數字的冪
- Java 程序:檢查數字是否為回文
- Java 程序:檢查數字是否為質數
- Java 程序:顯示兩個時間間隔之間的質數
- Java 程序:檢查阿姆斯特朗數
- Java 程序:顯示兩個間隔之間的阿姆斯特朗數
- Java 程序:使用函數顯示間隔之間的質數
- Java 程序:使用函數顯示間隔之間的阿姆斯特朗數
- Java 程序:以顯示數字的因數
- Java 程序:使用switch...case創建一個簡單的計算器
- Java 程序:檢查一個數字是否可以表示為兩個質數之和
- Java 程序:使用遞歸查找自然數之和
- Java 程序:使用遞歸查找數字的階乘
- Java 程序:使用遞歸查找 GCD
- Java 程序:將二進制數轉換為十進制,反之亦然
- Java 程序:將八進制數轉換為十進制,反之亦然
- Java 程序:將二進制數轉換為八進制,反之亦然
- Java 程序:使用遞歸來反轉句子
- Java 程序:使用遞歸來計算冪
- Java 程序:使用數組計算平均值
- Java 程序:查找數組的最大元素
- Java 程序:計算標準差
- Java 程序:使用多維數組相加兩個矩陣
- Java 程序:使用多維數組相乘矩陣
- Java 程序:通過將矩陣傳遞給函數來將兩個矩陣相乘
- Java 程序:查找矩陣轉置
- Java 程序:查找字符串中字符的頻率
- Java 程序:計算句子中元音和輔音的數量
- Java 程序:按字典順序對元素進行排序
- Java 程序:通過將對象傳遞給函數來相加兩個復數
- Java 程序:計算兩個時間段之間的差異
- Java 程序:從字符串中刪除所有空格
- Java 程序:打印數組
- Java 程序:將字符串轉換為日期
- Java 程序:將數字四舍五入到 n 個小數位
- Java 程序:連接兩個數組
- Java 程序:將字符轉換為字符串,反之亦然
- Java 程序:檢查數組是否包含給定值
- Java 程序:檢查字符串是否為空或null
- Java 程序:獲取當前日期/時間
- Java 程序:將毫秒轉換為分鐘和秒
- Java 程序:相加兩個日期
- Java 程序:連接兩個列表
- Java 程序:將列表(ArrayList)轉換為數組,反之亦然
- Java 程序:獲取當前工作目錄
- Java 程序:將映射(HashMap)轉換為列表
- Java 程序:將數組轉換為集(HashSet),反之亦然
- Java 程序:將字節數組轉換為十六進制
- Java 程序:從文件內容創建字符串
- Java 程序:將文本附加到現有文件
- Java 程序:將棧跟蹤轉換為字符串
- Java 程序:將文件轉換為字節數組,反之亦然
- Java 程序:將InputStream轉換為字符串
- Java 程序:將OutputStream轉換為字符串
- Java 程序:按字符串值查找枚舉
- Java 程序:比較字符串
- Java 程序:按值對映射進行排序
- Java 程序:按屬性對自定義對象的ArrayList進行排序
- Java 程序:檢查字符串是否為數字
- Java 程序:創建目錄
- Java 程序:重命名文件
- Java 程序:列出目錄中的文件
- Java 程序:復制文件
- Programiz Kotlin 教程
- Kotlin 簡介
- Kotlin HelloWorld - 您的 Kotlin 程序
- Kotlin 變量和原始類型
- Kotlin 運算符
- Kotlin 類型轉換
- Kotlin 表達式,語句和塊
- Kotlin 注釋
- Kotlin 基本輸入/輸出
- Kotlin 流程控制
- Kotlin if表達式
- Kotlin when表達式
- Kotlin while和do...while循環
- Kotlin for循環
- Kotlin break表達式
- Kotlin continue表達式
- Kotlin 函數
- Kotlin 函數
- Kotlin 中綴函數調用
- Kotlin 默認和命名參數
- Kotlin 遞歸(遞歸函數)和尾遞歸
- Kotlin OOP
- Kotlin 類和對象
- Kotlin 構造器
- Kotlin 獲取器和設置器
- Kotlin 繼承
- Kotlin 可見性修飾符
- Kotlin 抽象類
- Kotlin 接口
- Kotlin 嵌套和內部類
- Kotlin 數據類
- Kotlin 密封類
- Kotlin 對象聲明和表達式
- Kotlin 伴隨對象
- Kotlin 擴展函數
- Kotlin 運算符重載
- Kotlin 示例
- Kotlin 程序:獲取當前日期/時間
- Kotlin 程序:將列表(ArrayList)轉換為Array,反之亦然
- Kotlin 程序:將字符串轉換為日期
- Kotlin 程序:按屬性對自定義對象的ArrayList進行排序
- Kotlin 程序:打印整數(由用戶輸入)
- Kotlin 程序:相加兩個整數
- Kotlin 程序:將兩個浮點數相乘
- Kotlin 程序:查找字符的 ASCII 值
- Kotlin 程序:計算商數和余數
- Kotlin 程序:交換兩個數字
- Kotlin 程序:檢查數字是偶數還是奇數
- Kotlin 程序:檢查字母是元音還是輔音
- Kotlin 程序:在三個數字中找到最大的一個
- Kotlin 程序:查找二次方程的所有根
- Kotlin 程序:檢查閏年
- Kotlin 程序:檢查數字是正數還是負數
- Kotlin 程序:檢查字符是否為字母
- Kotlin 程序:計算自然數之和
- Kotlin 程序:查找數字的階乘
- Kotlin 程序:生成乘法表
- Kotlin 程序:展示斐波那契數列
- Kotlin 程序:查找兩個數字的 GCD
- Kotlin 程序:查找兩個數字的 LCM
- Kotlin 程序:使用循環從 A 到 Z 顯示字符
- Kotlin 程序:計算整數位數
- Kotlin 程序:反轉數字
- Kotlin 程序:計算數字的冪
- Kotlin 程序:檢查數字是否為回文
- Kotlin 程序:檢查數字是否為質數
- Kotlin 程序:顯示兩個間隔之間的質數
- Kotlin 程序:檢查阿姆斯特朗數
- Kotlin 程序:顯示兩個間隔之間的阿姆斯特朗數
- Kotlin 程序:使用函數顯示間隔之間的質數
- Kotlin 程序:使用函數顯示間隔之間的阿姆斯特朗數
- Kotlin 程序:顯示數字因數
- Kotlin 程序:使用switch...case制作一個簡單的計算器
- Kotlin 程序:檢查一個數字是否可以表示為兩個質數之和
- Kotlin 程序:使用遞歸找到自然數之和
- Kotlin 程序:使用遞歸查找數字的階乘
- Kotlin 程序:使用遞歸查找 GCD
- Kotlin 程序:將二進制數轉換為十進制,反之亦然
- Kotlin 程序:將八進制數轉換為十進制,反之亦然
- Kotlin 程序:將二進制數轉換為八進制,反之亦然
- Kotlin 程序:使用遞歸來反轉句子
- Kotlin 程序:使用遞歸來計算冪
- Kotlin 程序:使用數組計算平均值
- Kotlin 程序:在數組中查找最大的元素
- Kotlin 程序:計算標準差
- Kotlin 程序:使用多維數組相加兩個矩陣
- Kotlin 程序:使用多維數組乘以矩陣
- Kotlin 程序:通過將矩陣傳遞給函數來將兩個矩陣相乘
- Kotlin 程序:查找矩陣的轉置
- Kotlin 程序:查找字符串中字符的頻率
- Kotlin 程序:計算句子中元音和輔音的數量
- Kotlin 程序:按字典順序(字典順序)對元素進行排序
- Kotlin 程序:通過將類傳遞給函數來相加兩個復數
- Kotlin 程序:計算兩個時間段之間的差異
- Kotlin 程序:創建金字塔和圖案
- Kotlin 程序:從字符串中刪除所有空格
- Kotlin 程序:打印數組
- Kotlin 程序:將數字四舍五入到 n 個小數位
- Kotlin 程序:連接兩個數組
- Kotlin 程序:將字符轉換為字符串并反之
- Kotlin 程序:檢查數組是否包含給定值
- Kotlin 程序:檢查字符串是否為空或null
- Kotlin 程序:將毫秒轉換為分鐘
- Kotlin 程序:相加兩個日期
- Kotlin 程序:連接兩個列表
- Kotlin 程序:獲取當前工作目錄
- Kotlin 程序:將映射(HashMap)轉換為列表
- Kotlin 程序:將數組轉換為Set(HashSet),反之亦然
- Kotlin 程序:將字節數組轉換為十六進制
- Kotlin 程序:從文件內容創建字符串
- Kotlin 程序:將文本附加到現有文件
- Kotlin 程序:將棧跟蹤轉換為字符串
- Kotlin 程序:將文件轉換為字節數組,反之亦然
- Kotlin 程序:將InputStream轉換為字符串
- Kotlin 程序:將OutputStream轉換為字符串
- Kotlin 程序:通過字符串值查找枚舉
- Kotlin 程序:比較字符串
- Kotlin 程序:按值對映射排序
- Kotlin 程序:檢查字符串是否為數字
- Programiz Python 教程
- Python 簡介
- 如何開始使用 Python?
- Python 關鍵字和標識符
- Python 語句,縮進和注釋
- Python 變量,常量和字面值
- Python 數據類型
- Python 類型轉換
- Python 輸入,輸出和導入
- Python 運算符
- Python 命名空間和范圍
- Python 流程控制
- Python if...else語句
- Python for循環
- Python While循環
- Python break和continue
- Python pass語句
- Python 函數
- Python 函數
- Python 函數參數
- Python 遞歸
- Python 匿名/ Lambda 函數
- Python 全局,局部和非局部變量
- Python global關鍵字
- Python 模塊
- Python 包
- Python 數據類型
- Python 數字,類型轉換和數學
- Python 列表
- Python 元組
- Python 字符串
- Python 集
- Python 字典
- Python 文件
- Python 文件 I/O
- Python 目錄和文件管理
- Python 錯誤和內置異常
- Python 使用try,except和finally語句的異常處理
- Python 自定義異常
- Python 對象和類
- Python 面向對象編程
- Python 對象和類
- Python 繼承
- Python 多重繼承
- Python 運算符重載
- Python 高級主題
- Python 迭代器
- Python 生成器
- Python 閉包
- Python 裝飾器
- Python @property裝飾器
- Python 正則表達式
- Python 日期時間
- Python 日期時間
- Python strftime()
- Python strptime()
- 如何在 Python 中獲取當前日期和時間?
- Python 獲取當前時間
- Python 日期時間到時間戳,反之亦然
- Python time模塊
- Python sleep()
- Python 示例
- Python 程序:檢查質數
- Python 程序:相加兩個數字
- Python 程序:查找數字階乘
- Python 程序:制作一個簡單的計算器
- Python 程序:打印 Helloworld
- Python 程序:查找平方根
- Python 程序:計算三角形的面積
- Python 程序:求解二次方程式
- Python 程序:交換兩個變量
- Python 程序:生成隨機數
- Python 程序:將公里轉換為英里
- Python 程序:將攝氏溫度轉換為華氏溫度
- Python 程序:檢查數字是正數,負數還是 0
- Python 程序:檢查數字是奇數還是偶數
- Python 程序:檢查閏年
- Python 程序:在三個數字中找到最大的
- Python 程序:檢查質數
- Python 程序:打印一個間隔內的所有質數
- Python 程序:查找數字階乘
- Python 程序:顯示乘法表
- Python 程序:打印斐波那契序列
- Python 程序:檢查阿姆斯特朗數
- Python 程序:查找間隔內的阿姆斯特朗數
- Python 程序:查找自然數總和
- Python 程序:使用匿名函數顯示 2 的冪
- Python 程序:查找可被另一個數整除的數字
- Python 程序:將十進制轉換為二進制,八進制和十六進制
- Python 程序:查找字符的 ASCII 值
- Python 程序:查找 HCF 或 GCD
- Python 程序:查找 LCM
- Python 程序:查找數字的因數
- Python 程序:制作一個簡單的計算器
- Python 程序:打亂紙牌
- Python 程序:顯示日歷
- Python 程序:使用遞歸顯示斐波那契數列
- Python 程序:使用遞歸查找自然數之和
- Python 程序:使用遞歸查找數字的階乘
- Python 程序:使用遞歸將十進制轉換為二進制
- Python 程序:相加兩個矩陣
- Python 程序:轉置矩陣
- Python 程序:將兩個矩陣相乘
- Python 程序:檢查字符串是否為回文
- Python 程序:從字符串中刪除標點符號
- Python 程序:按字母順序對單詞進行排序
- Python 程序:演示不同的集合操作
- Python 程序:計算每個元音的數量
- Python 程序:合并郵件
- Python 程序:查找圖像的大小(分辨率)
- Python 程序:查找文件哈希
- Programiz Swift 教程
- Swift 介紹
- Swift HelloWorld 程序
- Swift 變量,常量和字面值
- Swift 數據類型
- Swift 可選項
- Swift 的字符和字符串
- Swift 基本輸入和輸出
- Swift 表達式,語句和代碼塊
- Swift 注釋
- Swift 運算符
- Swift 運算符
- Swift 運算符的優先級和關聯性
- Swift 三元條件運算符
- Swift 按位和移位運算符
- Seift 流程控制
- Swift if,if...else語句
- switch語句
- Swift for-in循環
- Swift while和repeat...while循環
- Swift 中的嵌套循環
- break語句
- continue語句
- Guard語句
- Swift 集合
- Swift 數組
- Swift 集
- Swift 字典
- Swift 函數
- Swift 函數
- Swift 函數參數和返回值
- Swift 嵌套函數
- Swift 遞歸
- Swift 范圍
- Swift 函數重載
- Swift 進階
- Swift 閉包
- Swift 類型別名