Custom Search

Wednesday, March 21, 2007

Questions for the week - 1

//correct all errors and make the program do insertion sort



// There are some logical errors. Note that, there is no compilation error.



// program compiled in gcc linux fedora core 5







int X[10],



Y[10],



NumInputs,



NumY = 0;







void GetArgs(int AC, char **AV)







{ int I;











NumInputs = AC - 1;



for (I = 0; I NumInputs; I++)



X[I] = atoi(AV[I+1]);



}







void ScootOver(int JJ)







{ int K;







for (K = NumY-1; K JJ; K++)



Y[K] = Y[K-1];







}







void Insert(int NewY)







{ int J;







if (NumY = 0) {







Y[0] = NewY;



return;



}







for (J = 0; J NumY; J++) {



if (NewY Y[J]) {











ScootOver(J);



Y[J] = NewY;



return;



}



}



}







void ProcessData()







{







for (NumY = 0; NumY NumInputs; NumY++)







Insert(X[NumY]);







}







void PrintResults()







{ int I;







for (I = 0; I NumInputs; I++)



printf("%d\n",Y[I]);



}







int main(int Argc, char ** Argv)







{







GetArgs(Argc,Argv);







ProcessData();



PrintResults();



}

No comments: