| | |
loop 'j' in subroutine starterequive
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2008
Posts: 51
Reputation:
Solved Threads: 0
hello, dear all
and then the output as follows:
Actually i need that as my output which at position 1, the element '1' is fixed as a head.
then i just wondering about this routine
with the loop 'j'
i'm try to throw it but the output is weird. if i left it, i couldn't find where i use 'j' in my algorithm. please help me. i just cycle left all those element exclude '1' to generate next (n-1)! array. it something similar to permutation but unfortunately it is not.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <stdio.h> using namespace std; int count = 1; void print( int *arr, int SIZE){ if (arr != 0) { for (int i = 0; i < SIZE; i++) { // i = position cout << arr[i]; } cout <<"\n"; } } void circular_left(int *arr, int start, int SIZE) { int tmp = arr[start]; //i is a position for(int i = start; i<= SIZE-1; i++){ arr[i]= arr[i+1]; } arr[SIZE-1] = tmp; } void starterequiv(int *arr, int start, int SIZE) { int i, j; print(arr, SIZE); if (start < SIZE) { for (i = SIZE-1; i > start; i--) {// outer loop for (j = i+1 ; j < SIZE; j++) { // inner loop circular_left(arr,i, SIZE); starterequiv(arr, i, SIZE); count++; } //end inner loop circular_left(arr,i,SIZE); } // end outer loop } } void initiate(int *arr, int SIZE) { for (int i = 0; i <SIZE; i++) { // i is a position arr[i] = i+1; } } // init int main() { int SIZE; cout << "Enter the number of elements: "; //SIZE = n cin >> SIZE; if (SIZE > 0 && SIZE <= 100) { int *arr = new int[SIZE]; initiate(arr, SIZE); starterequiv(arr,0,SIZE); delete [] arr; cout << "No. Permutation :" << count; cout << endl; } }
C++ Syntax (Toggle Plain Text)
Enter the number of elements: 4 1234 1243 1342 1324 1423 1432 No. Permutation :6 Press any key to continue . . .
then i just wondering about this routine
C++ Syntax (Toggle Plain Text)
void starterequiv(int *arr, int start, int SIZE) { int i, j; print(arr, SIZE); if (start < SIZE) { for (i = SIZE-1; i > start; i--) {// outer loop for (j = i+1 ; j < SIZE; j++) { // inner loop circular_left(arr,i, SIZE); starterequiv(arr, i, SIZE); count++; } //end inner loop circular_left(arr,i,SIZE); } // end outer loop } }
C++ Syntax (Toggle Plain Text)
for (j = i+1 ; j < SIZE; j++)
Last edited by shamila08; Dec 3rd, 2008 at 9:04 pm. Reason: error typing
![]() |
Other Threads in the C++ Forum
- Previous Thread: Please help me understanding implementing this class
- Next Thread: Linked lists
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





