From b16c702e15d3df2956ca75fa8fc1c8f4be3b7bc0 Mon Sep 17 00:00:00 2001 From: Ritik Nandwal Date: Wed, 12 May 2021 01:24:21 +0530 Subject: [PATCH] Add sorting question having graph approach --- graph/minSwapstoSort.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 graph/minSwapstoSort.cpp diff --git a/graph/minSwapstoSort.cpp b/graph/minSwapstoSort.cpp new file mode 100644 index 0000000..95ceb65 --- /dev/null +++ b/graph/minSwapstoSort.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; +int minSwaps(int ar[],int n){ + vector> p(n); + for(int i = 0 ; i < n ; i++){ + p[i].first=ar[i]; + p[i].second=i; + } + // for(auto x:p) + // cout< vis(n,false); + for(int i=0;i