The program works on visual studio without the command line parameters. But the code has to be executed through the linux terminal using ./a.out m n p
The logic is fine it works except it will not compile in the terminal. If anyone out there is familiar with linux command line execution and can help me with the syntax it would be greatly appreciated.
Thanks.
#include <iostream>
#include <stdlib>
#include <cstring>
using namespace std;
struct node{
int item;
node* next;
node(int x, node* t){
item = x;
next = t;
}
};
typedef node *link;
int main(int argc, char *argv[]){
int i;
int N = atoi(argv[1]);
int M;
int count = 1;
int m = atoi(argv[2]);
int p = atoi(argv[3]);
link t;
t = new node(1, 0);
t->next = t;
link x;
x= t;
for(i = 2; i <= N; i++)
x = (x->next = new node(i, t));
while(x != x->next){
if(count % 2 == 1){
M = m;
}
else{
M = p;
}
for(i = 1; i<M; i++){
x = x->next;
}
x->next = x->next->next;
count++;
}
cout<< x->item << endl;
}

New Topic/Question
Reply




MultiQuote



|