c_cpp 部分评论

保存自https://webdevstudios.com/2016/08/16/snippets-saved-life-how-sublime-text-3-snippets-changed-everything/

partcomm.c
<snippet>
    <!-- Type `partialcomment` or `pcomment` and hit tab to output a comment block. -->
    <!-- Type a short description of your partial and you're good to go! -->
    <content><![CDATA[
//--------------------------------------------------------------
// ${1:Partial Description}
//--------------------------------------------------------------
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>partialcomment</tabTrigger>
    <tabTrigger>pcomment</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>source.scss</scope>
</snippet>

c_cpp 最长的子序列

最长不下降子序列<br/> <br/> ## Q <br/> <br/>在一个数字序列中,找到一个最长的子序列(可以不连续),使得这个子序列是不下降(非递减)的。<br/> <br/>``` <br/>样本输入:<br/> 7 <br/> 1 2 3 -1 -2 7 9 <br/>样本输出: <br/> 5(1 2 3 7 9)<br/>``` <br/> <br/> ## A <br/> <br/> - `dp [i]`:以`A [ i]`结尾的最长不下降子序列的长度<br/> - `return * max_element(dp,dp + n);`<br/> - `dp [i] = max {1,dp [j] + 1},j = 1,2,...,i-1 && A [j] <A [i]`<br/> - `dp [i] = 1,1 <= i <= n` <br/> - `O(n ^ 2)`<br/> <br/>``` <br/> 1 2 3 4 5 6 7 <br/> 1 2 3 -1 -2 7 9 <br/>``` <br/> <br/>``` <br/> dp [1] = 1 <br/> dp [2] = max {1,dp [1] + 1} = max {1, 2} = 2 <br/> dp [3] = max {1,dp [1] + 1,dp [2] + 1} = max {1,2,3} = 3 <br/> dp [4] = 1 <br/> dp [5] = 1 <br/> dp [6] = max {1,dp [1] + 1,dp [2] + 1,dp [3] + 1,dp [4] + 1,dp [5] + 1} <br/> = max {1,2,3,4,1,1} = 4 <br/> dp [7] = max {1,dp [1] + 1 ,dp [2] + 1,dp [3] + 1,dp [4] + 1,dp [5] + 1,dp [6] + 1} <br/> = max {1,2,3,4,1,5,5} = 5 <br/>``` <br/> <br/>

LIS.cpp
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 100;
int A[N], dp[N];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> A[i];
	}
	int ans = -1;	// Record the maximum of dp[i]
	for (int i = 1; i <= n; i++) {	// calculate dp[i] in order
		dp[i] = 1;
		for (int j = 1; j < i; j++) {
			if (A[i] >= A[j] && (dp[j] + 1 > dp[i])) {
				dp[i] = dp[j] + 1;	// state transition equation, used to update dp[i] 
			}
		}
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
	return 0;
}

/*
Sample Input:
8 
1 2 3 -9 3 9 0 11 
Sample Output:
6 // 1 2 3 3 9 11
*/

c_cpp 30天代码HackerRank

Ejercicios realizados en el curso 30天代码de HackerRank <br/>

day1_DataTypes.cpp
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    int i = 4;
    double d = 4.0;
    string s = "HackerRank ";
    // Declare second integer, double, and String variables.
    int i2 = 0;
    double d2 = 0.0;
    string s2 = "";
    // Read and save an integer, double, and String to your variables.
    cin >> i2;
    cin >> d2;
    getline(cin >> ws, s2);
    // Note: If you have trouble reading the entire string, please go back and review the Tutorial closely.
    // Print the sum of both integer variables on a new line.
    cout << i + i2 << endl;
    // Print the sum of the double variables on a new line.
    cout << fixed << setprecision(1) << d + d2 << endl;
    // Concatenate and print the String variables on a new line
    cout << s + s2 << endl;
    // The 's' variable above should be printed first.
    return 0;
}

c_cpp DFS

dfs.cpp
#include <iostream>
#include <vector>
using namespace std;
const int MAX_N = 100;

struct Node {
	int no, weight;
	vector<int> children;
} node[MAX_N];
vector<vector<int>> res;
vector<int> v1;

void dfs(int c, int s) {
	for (int i = 0; i < node[c].children.size(); i++) {
		v1.push_back(node[c].children[i]);
		s -= node[c].weight;
		dfs(node[c].children[i], s);
		s += node[c].weight;
		v1.pop_back();
	}
	if (!node[c].children.size() && s == node[c].weight) {
		res.push_back(v1);
	}
}

int main() {
	node[0].weight = 10;
	node[1].weight = 2;
	node[2].weight = 5;
	node[3].weight = 8;
	node[4].weight = 3;
	node[5].weight = 8;
	node[0].children.push_back(1);
	node[0].children.push_back(2);
	node[0].children.push_back(3);
	node[2].children.push_back(4);
	node[2].children.push_back(5);
	//       10(0)
	//      /  |  \
	//     /   |   \
	//    /    |    \
	//  2(1)  5(2)  8(3)
	//       /   \
	//      /     \
	//     /       \
	//   3(4)      8(5)
	dfs(0, 18);

	for (auto vec : res) {
		cout << 0 << " ";
		for (auto val : vec) {
			cout << val << " ";
		}
		cout << endl;
	}
	// 0 2 4
	// 0 3
}

c_cpp C

double.c
double a;
scanf("%lf",&a);
printf("%f",a);

c_cpp 演示

.cpp
#include<iostream>
using namespace std;
int main(){
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++){}
  return 0;
}
/*
printf("%d",c);
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<set>
*/

c_cpp 地图::计数()

size_type count(const key_type&k)const; <br/> <br/>`O(log n)`<br/> <br/> **计算具有特定键的元素** <br/> <br/> - 使用键搜索容器中的元素相当于k并返回匹配数。 <br/> <br/> - 因为映射容器中的所有元素都是唯一的,所以函数只能返回1(如果找到元素)或零(否则)。 <br/> <br/>

count.cpp
#include <iostream>
#include <map>
using namespace std;

int main() {
	map<int, int> map1;

	map1.insert(pair<int, int>(1, 1));
	map1.insert(pair<int, int>(2, 1));

	for (auto it : map1) {
		cout << it.first << " " << it.second << endl;
	}
	/*
	 * 1 1
	 * 2 1 
	 */

	cout << map1.count(1) << endl; // 1
	cout << map1.count(2) << endl; // 1
	cout << map1.count(3) << endl; // 0
}

c_cpp 地图::找到();

迭代器find(const key_type&k); <br/> <br/>获取元素的迭代器<br/> <br/>在容器中搜索一个等价于k的键的元素,如果找到则返回一个迭代器,否则它返回一个迭代器来映射::结束。

find.cpp
// map::find
#include <iostream>
#include <map>
using namespace std;

int main() {
	map<char, int> map1;
	map<char, int>::iterator it;

	map1['a'] = 50;
	map1['b'] = 100;
	map1['c'] = 150;
	map1['d'] = 200;

	it = map1.find('b');
	if (it != map1.end()) {
		map1.erase(it);
	}

	// print content:
	cout << "a => " << map1.find('a')->second << endl;
	cout << "c => " << map1.find('c')->second << endl;
	cout << "d => " << map1.find('d')->second << endl;

	return 0;
}

c_cpp A *算法(C ++)

- [参考链接2](https://blog.csdn.net/yuxuan20062007/article/details/86767355)

a_star.h
#ifndef ASTAR_H
#define ASTAR_H
#include <iostream>
#include <queue>
#include <vector>
#include <stack>
#include<algorithm>
using namespace std;
 
typedef struct Node
{
	int x,y;
	int g; //起始点到当前点实际代价
	int h;//当前节点到目标节点最佳路径的估计代价
	int f;//估计值
	Node* father;
	Node(int x,int y)
	{
		this->x = x;
		this->y = y ;
		this->g = 0;
		this->h = 0;
		this->f = 0;
		this->father = NULL;
	}
	Node(int x,int y,Node* father)
	{
		this->x = x;
		this->y = y ;
		this->g = 0;
		this->h = 0;
		this->f = 0;
		this->father = father;
	}
}Node;
 
class Astar{
public:
	Astar();
	~Astar();
	void search(Node* startPos,Node* endPos);
	void checkPoit(int x,int y,Node* father,int g);
	void NextStep(Node* currentPoint);
	int isContains(vector<Node*>* Nodelist ,int x,int y);
	void countGHF(Node* sNode,Node* eNode,int g);
	static bool compare(Node* n1,Node* n2);
	bool unWalk(int x,int y);
	void printPath(Node* current);
	void printMap();
	vector<Node*> openList;
	vector<Node*> closeList;
	Node *startPos;
	Node *endPos;
	static const int WeightW = 10;// 正方向消耗
	static const int WeightWH = 14;//打斜方向的消耗
	static const int row = 6;
	static const int col = 8;
};
#endif
a_star.cpp
#include "stdafx.h"
#include "Astar.h"
int map[101][101] =
{
	{0,0,0,1,0,1,0,0,0},
	{0,0,0,1,0,1,0,0,0},
	{0,0,0,0,0,1,0,0,0},
	{0,0,0,1,0,1,0,1,0},
	{0,0,0,1,0,1,0,1,0},
	{0,0,0,1,0,0,0,1,0},
	{0,0,0,1,0,0,0,1,0}
};
Astar::Astar()
{
}
Astar::~Astar()
{
}
void Astar::search( Node* startPos,Node* endPos )
{
	if (startPos->x < 0 || startPos->x > row || startPos->y < 0 || startPos->y >col
		||
		endPos->x < 0 || endPos->x > row || endPos->y < 0 || endPos->y > col)
		return ;
	Node* current;
	this->startPos = startPos;
	this->endPos = endPos;
	openList.push_back(startPos);
	//主要是这块,把开始的节点放入openlist后开始查找旁边的8个节点,如果坐标超长范围或在closelist就return 如果已经存在openlist就对比当前节点到遍历到的那个节点的G值和当前节点到原来父节点的G值 如果原来的G值比较大 不用管 否则重新赋值G值 父节点 和f 如果是新节点 加入到openlist直到opellist为空或找到终点
	while(openList.size() > 0)
	{
		current = openList[0];
		if (current->x == endPos->x && current->y == endPos->y)
		{
			cout<<"find the path"<<endl;
			printMap();
			printPath(current);
			openList.clear();
			closeList.clear();
			break;
		}
		NextStep(current);
		closeList.push_back(current);
		openList.erase(openList.begin());
		sort(openList.begin(),openList.end(),compare);
	}
}
void Astar::checkPoit( int x,int y,Node* father,int g)
{
	if (x < 0 || x > row || y < 0 || y > col)
		return;
	if (this->unWalk(x,y))
		return;
	if (isContains(&closeList,x,y) != -1)
		return;
	int index;
	if ((index = isContains(&openList,x,y)) != -1)
	{
		Node *point = openList[index];
		if (point->g > father->g + g)
		{
			point->father = father;
			point->g = father->g + g;
			point->f = point->g + point->h;
		}
	}
	else
	{
		Node * point = new Node(x,y,father);
		countGHF(point,endPos,g);
		openList.push_back(point);
	}
}
void Astar::NextStep( Node* current )
{
	checkPoit(current->x - 1,current->y,current,WeightW);//左
	checkPoit(current->x + 1,current->y,current,WeightW);//右
	checkPoit(current->x,current->y + 1,current,WeightW);//上
	checkPoit(current->x,current->y - 1,current,WeightW);//下
	checkPoit(current->x - 1,current->y + 1,current,WeightWH);//左上
	checkPoit(current->x - 1,current->y - 1,current,WeightWH);//左下
	checkPoit(current->x + 1,current->y - 1,current,WeightWH);//右下
	checkPoit(current->x + 1,current->y + 1,current,WeightWH);//右上
}
int Astar::isContains(vector<Node*>* Nodelist, int x,int y )
{
	for (int i = 0;i < Nodelist->size();i++)
	{
		if (Nodelist->at(i)->x == x && Nodelist->at(i)->y == y)
		{
			return i;
		}
	}
	return -1;
}
void Astar::countGHF( Node* sNode,Node* eNode,int g)
{
	int h = abs(sNode->x - eNode->x) * WeightW + abs(sNode->y - eNode->y) * WeightW;
	int currentg = sNode->father->g + g;
	int f = currentg + h;
	sNode->f = f;
	sNode->h = h;
	sNode->g = currentg;
}
bool Astar::compare( Node* n1,Node* n2 )
{
	//printf("%d,%d",n1->f,n2->f);
	return n1->f < n2->f;
}
bool Astar::unWalk( int x,int y)
{
	if (map[x][y] == 1)
		return true;
	return false;
}
void Astar::printPath( Node* current )
{
	if (current->father != NULL)
		printPath(current->father);
	map[current->x][current->y] = 6;
	printf("(%d,%d)",current->x,current->y);
}
void Astar::printMap()
{
	for(int i=0;i<=row;i++){
		for(int j=0;j<=col;j++){
			printf("%d ",map[i][j]);
		}
		printf("\n");
	}
}
main.cpp
// Astar.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//
 
#include "stdafx.h"
#include "Astar.h"
 
int _tmain(int argc, _TCHAR* argv[])
{
	Astar astar;
	Node *startPos = new Node(5,1);
	Node *endPos = new Node(3,8);
 
	//astar.printMap();
	astar.search(startPos,endPos);
	cout<<endl;
	astar.printMap();
	system("pause");
	return 0;
}
 

c_cpp Dijsktra的算法

- [邻接矩阵](https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-greedy-algo-7/) <br/> - [邻接表](https://www.geeksforgeeks.org / dijkstras算法换邻接一览表示贪婪-ALGO-8 /)

adjacency_matrix.cpp
// A C++ program for Dijkstra's single source shortest path algorithm.
// The program is for adjacency matrix representation of the graph

#include <stdio.h>
#include <limits.h>

// Number of vertices in the graph
#define V 9

// A utility function to find the vertex with minimum distance value, from
// the set of vertices not yet included in shortest path tree
int minDistance(int dist[], bool sptSet[])
{
    // Initialize min value
    int min = INT_MAX, min_index;

    for (int v = 0; v < V; v++)
        if (sptSet[v] == false && dist[v] <= min)
            min = dist[v], min_index = v;

    return min_index;
}

// A utility function to print the constructed distance array
int printSolution(int dist[], int n)
{
    printf("Vertex Distance from Source\n");
    for (int i = 0; i < V; i++)
        printf("%d tt %d\n", i, dist[i]);
}

// Function that implements Dijkstra's single source shortest path algorithm
// for a graph represented using adjacency matrix representation
void dijkstra(int graph[V][V], int src)
{
    int dist[V]; // The output array. dist[i] will hold the shortest
        // distance from src to i

    bool sptSet[V]; // sptSet[i] will be true if vertex i is included in shortest
        // path tree or shortest distance from src to i is finalized

    // Initialize all distances as INFINITE and stpSet[] as false
    for (int i = 0; i < V; i++)
        dist[i] = INT_MAX, sptSet[i] = false;

    // Distance of source vertex from itself is always 0
    dist[src] = 0;

    // Find shortest path for all vertices
    for (int count = 0; count < V - 1; count++)
    {
        // Pick the minimum distance vertex from the set of vertices not
        // yet processed. u is always equal to src in the first iteration.
        int u = minDistance(dist, sptSet);

        // Mark the picked vertex as processed
        sptSet[u] = true;

        // Update dist value of the adjacent vertices of the picked vertex.
        for (int v = 0; v < V; v++)

            // Update dist[v] only if is not in sptSet, there is an edge from
            // u to v, and total weight of path from src to v through u is
            // smaller than current value of dist[v]
            if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX && dist[u] + graph[u][v] < dist[v])
                dist[v] = dist[u] + graph[u][v];
    }

    // print the constructed distance array
    printSolution(dist, V);
}

// driver program to test above function
int main()
{
    /* Let us create the example graph discussed above */
    int graph[V][V] = {{0, 4, 0, 0, 0, 0, 0, 8, 0},
                       {4, 0, 8, 0, 0, 0, 0, 11, 0},
                       {0, 8, 0, 7, 0, 4, 0, 0, 2},
                       {0, 0, 7, 0, 9, 14, 0, 0, 0},
                       {0, 0, 0, 9, 0, 10, 0, 0, 0},
                       {0, 0, 4, 14, 10, 0, 2, 0, 0},
                       {0, 0, 0, 0, 0, 2, 0, 1, 6},
                       {8, 11, 0, 0, 0, 0, 1, 0, 7},
                       {0, 0, 2, 0, 0, 0, 6, 7, 0}};

    dijkstra(graph, 0);

    return 0;
}
adjacency_list.cpp
// C / C++ program for Dijkstra's shortest path algorithm for adjacency
// list representation of graph

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

// A structure to represent a node in adjacency list
struct AdjListNode
{
    int dest;
    int weight;
    struct AdjListNode *next;
};

// A structure to represent an adjacency liat
struct AdjList
{
    struct AdjListNode *head; // pointer to head node of list
};

// A structure to represent a graph. A graph is an array of adjacency lists.
// Size of array will be V (number of vertices in graph)
struct Graph
{
    int V;
    struct AdjList *array;
};

// A utility function to create a new adjacency list node
struct AdjListNode *newAdjListNode(int dest, int weight)
{
    struct AdjListNode *newNode =
        (struct AdjListNode *)malloc(sizeof(struct AdjListNode));
    newNode->dest = dest;
    newNode->weight = weight;
    newNode->next = NULL;
    return newNode;
}

// A utility function that creates a graph of V vertices
struct Graph *createGraph(int V)
{
    struct Graph *graph = (struct Graph *)malloc(sizeof(struct Graph));
    graph->V = V;

    // Create an array of adjacency lists. Size of array will be V
    graph->array = (struct AdjList *)malloc(V * sizeof(struct AdjList));

    // Initialize each adjacency list as empty by making head as NULL
    for (int i = 0; i < V; ++i)
        graph->array[i].head = NULL;

    return graph;
}

// Adds an edge to an undirected graph
void addEdge(struct Graph *graph, int src, int dest, int weight)
{
    // Add an edge from src to dest. A new node is added to the adjacency
    // list of src. The node is added at the begining
    struct AdjListNode *newNode = newAdjListNode(dest, weight);
    newNode->next = graph->array[src].head;
    graph->array[src].head = newNode;

    // Since graph is undirected, add an edge from dest to src also
    newNode = newAdjListNode(src, weight);
    newNode->next = graph->array[dest].head;
    graph->array[dest].head = newNode;
}

// Structure to represent a min heap node
struct MinHeapNode
{
    int v;
    int dist;
};

// Structure to represent a min heap
struct MinHeap
{
    int size;     // Number of heap nodes present currently
    int capacity; // Capacity of min heap
    int *pos;     // This is needed for decreaseKey()
    struct MinHeapNode **array;
};

// A utility function to create a new Min Heap Node
struct MinHeapNode *newMinHeapNode(int v, int dist)
{
    struct MinHeapNode *minHeapNode =
        (struct MinHeapNode *)malloc(sizeof(struct MinHeapNode));
    minHeapNode->v = v;
    minHeapNode->dist = dist;
    return minHeapNode;
}

// A utility function to create a Min Heap
struct MinHeap *createMinHeap(int capacity)
{
    struct MinHeap *minHeap =
        (struct MinHeap *)malloc(sizeof(struct MinHeap));
    minHeap->pos = (int *)malloc(capacity * sizeof(int));
    minHeap->size = 0;
    minHeap->capacity = capacity;
    minHeap->array =
        (struct MinHeapNode **)malloc(capacity * sizeof(struct MinHeapNode *));
    return minHeap;
}

// A utility function to swap two nodes of min heap. Needed for min heapify
void swapMinHeapNode(struct MinHeapNode **a, struct MinHeapNode **b)
{
    struct MinHeapNode *t = *a;
    *a = *b;
    *b = t;
}

// A standard function to heapify at given idx
// This function also updates position of nodes when they are swapped.
// Position is needed for decreaseKey()
void minHeapify(struct MinHeap *minHeap, int idx)
{
    int smallest, left, right;
    smallest = idx;
    left = 2 * idx + 1;
    right = 2 * idx + 2;

    if (left < minHeap->size &&
        minHeap->array[left]->dist < minHeap->array[smallest]->dist)
        smallest = left;

    if (right < minHeap->size &&
        minHeap->array[right]->dist < minHeap->array[smallest]->dist)
        smallest = right;

    if (smallest != idx)
    {
        // The nodes to be swapped in min heap
        MinHeapNode *smallestNode = minHeap->array[smallest];
        MinHeapNode *idxNode = minHeap->array[idx];

        // Swap positions
        minHeap->pos[smallestNode->v] = idx;
        minHeap->pos[idxNode->v] = smallest;

        // Swap nodes
        swapMinHeapNode(&minHeap->array[smallest], &minHeap->array[idx]);

        minHeapify(minHeap, smallest);
    }
}

// A utility function to check if the given minHeap is ampty or not
int isEmpty(struct MinHeap *minHeap)
{
    return minHeap->size == 0;
}

// Standard function to extract minimum node from heap
struct MinHeapNode *extractMin(struct MinHeap *minHeap)
{
    if (isEmpty(minHeap))
        return NULL;

    // Store the root node
    struct MinHeapNode *root = minHeap->array[0];

    // Replace root node with last node
    struct MinHeapNode *lastNode = minHeap->array[minHeap->size - 1];
    minHeap->array[0] = lastNode;

    // Update position of last node
    minHeap->pos[root->v] = minHeap->size - 1;
    minHeap->pos[lastNode->v] = 0;

    // Reduce heap size and heapify root
    --minHeap->size;
    minHeapify(minHeap, 0);

    return root;
}

// Function to decreasy dist value of a given vertex v. This function
// uses pos[] of min heap to get the current index of node in min heap
void decreaseKey(struct MinHeap *minHeap, int v, int dist)
{
    // Get the index of v in heap array
    int i = minHeap->pos[v];

    // Get the node and update its dist value
    minHeap->array[i]->dist = dist;

    // Travel up while the complete tree is not hepified.
    // This is a O(Logn) loop
    while (i && minHeap->array[i]->dist < minHeap->array[(i - 1) / 2]->dist)
    {
        // Swap this node with its parent
        minHeap->pos[minHeap->array[i]->v] = (i - 1) / 2;
        minHeap->pos[minHeap->array[(i - 1) / 2]->v] = i;
        swapMinHeapNode(&minHeap->array[i], &minHeap->array[(i - 1) / 2]);

        // move to parent index
        i = (i - 1) / 2;
    }
}

// A utility function to check if a given vertex
// 'v' is in min heap or not
bool isInMinHeap(struct MinHeap *minHeap, int v)
{
    if (minHeap->pos[v] < minHeap->size)
        return true;
    return false;
}

// A utility function used to print the solution
void printArr(int dist[], int n)
{
    printf("Vertex Distance from Source\n");
    for (int i = 0; i < n; ++i)
        printf("%d \t\t %d\n", i, dist[i]);
}

// The main function that calulates distances of shortest paths from src to all
// vertices. It is a O(ELogV) function
void dijkstra(struct Graph *graph, int src)
{
    int V = graph->V; // Get the number of vertices in graph
    int dist[V];      // dist values used to pick minimum weight edge in cut

    // minHeap represents set E
    struct MinHeap *minHeap = createMinHeap(V);

    // Initialize min heap with all vertices. dist value of all vertices
    for (int v = 0; v < V; ++v)
    {
        dist[v] = INT_MAX;
        minHeap->array[v] = newMinHeapNode(v, dist[v]);
        minHeap->pos[v] = v;
    }

    // Make dist value of src vertex as 0 so that it is extracted first
    minHeap->array[src] = newMinHeapNode(src, dist[src]);
    minHeap->pos[src] = src;
    dist[src] = 0;
    decreaseKey(minHeap, src, dist[src]);

    // Initially size of min heap is equal to V
    minHeap->size = V;

    // In the followin loop, min heap contains all nodes
    // whose shortest distance is not yet finalized.
    while (!isEmpty(minHeap))
    {
        // Extract the vertex with minimum distance value
        struct MinHeapNode *minHeapNode = extractMin(minHeap);
        int u = minHeapNode->v; // Store the extracted vertex number

        // Traverse through all adjacent vertices of u (the extracted
        // vertex) and update their distance values
        struct AdjListNode *pCrawl = graph->array[u].head;
        while (pCrawl != NULL)
        {
            int v = pCrawl->dest;

            // If shortest distance to v is not finalized yet, and distance to v
            // through u is less than its previously calculated distance
            if (isInMinHeap(minHeap, v) && dist[u] != INT_MAX &&
                pCrawl->weight + dist[u] < dist[v])
            {
                dist[v] = dist[u] + pCrawl->weight;

                // update distance value in min heap also
                decreaseKey(minHeap, v, dist[v]);
            }
            pCrawl = pCrawl->next;
        }
    }

    // print the calculated shortest distances
    printArr(dist, V);
}

// Driver program to test above functions
int main()
{
    // create the graph given in above fugure
    int V = 9;
    struct Graph *graph = createGraph(V);
    addEdge(graph, 0, 1, 4);
    addEdge(graph, 0, 7, 8);
    addEdge(graph, 1, 2, 8);
    addEdge(graph, 1, 7, 11);
    addEdge(graph, 2, 3, 7);
    addEdge(graph, 2, 8, 2);
    addEdge(graph, 2, 5, 4);
    addEdge(graph, 3, 4, 9);
    addEdge(graph, 3, 5, 14);
    addEdge(graph, 4, 5, 10);
    addEdge(graph, 5, 6, 2);
    addEdge(graph, 6, 7, 1);
    addEdge(graph, 6, 8, 6);
    addEdge(graph, 7, 8, 7);

    dijkstra(graph, 0);

    return 0;
}