Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void findcycles(int** array, char* cyc, int colsCnt, int arraylen){
- int ind = 0;
- int *visited = new int[colsCnt];
- visited[colsCnt] = {0};
- int *fx = new int[colsCnt];
- for(int i = 0; i<colsCnt; i++){
- fx[i] = array[1][i];
- }
- for(int i = 1; i<colsCnt; i++){
- if(visited[i]!=1){
- cyc[ind] = '('; //start cycle with (
- cout << cyc[ind] << " ";
- ind++;
- while(visited[i]!=1){ //while the current element was not visited
- cyc[ind] =(char) (fx[i] + '0'); // make element cycle element (cast it to char first)
- cout << cyc[ind] << " ";
- visited[i] = 1; // check out the position of the element just visited
- ind++;
- i = findInd(array, colsCnt, fx[i]); //find position of next element of cycle
- }
- cyc[ind] = ')'; // close cycle with )
- cout << cyc[ind] << " ";
- ind++;
- }
- if(visited[i] == 1){
- continue;
- }
- cyc[ind] = (char)(fx[i] + '0');
- cout << cyc[ind] << " ";
- ind++;
- arraylen = ind;
- }
- }
- int findInd(int **array, int colsCnt, int element){
- for(int i = 0; i<colsCnt; i++){
- if(array[0][i] == element){
- return i;
- }
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement