-
-
Save ShivendraAgrawal/6105383 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "iostream" | |
using namespace std; | |
void find_next(int num[], int n); | |
int main() | |
{ | |
int n; | |
printf("enter n\n"); | |
scanf("%d",&n); | |
printf("enter %d-digit no.\n",n); | |
int num[n]; | |
for(int i =0;i<n;i++) | |
{ | |
scanf("%d",&num[i]); | |
} | |
int i=n-1; | |
if(n!=1) | |
find_next(num,n,i); | |
else | |
find_next(num,n,i-1); | |
} | |
void find_next(int num[], int n,i) | |
{ | |
for(int j=i-1;j>0;j--) | |
{ | |
if(num[i]>num[j] && num[j]!=n) | |
swap(num[i],num[j]); | |
arrange_inc(num,j+1); | |
break; | |
if(num[j]==n && num[j-1]>num[i]) | |
swap(num[j],num[j-1]); | |
break; | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment