Xcode では、いくつかのポイント (X、Y) がユーザーによって与えられるグラフを作成しようとしています。ユーザーは、グラフにプロットするポイントの数を選択できます。X 軸のポイントを NSMutableArray に保存し、Y 軸のポイントを NSMutableArray に保存しましたが、これらを昇順に並べ替える必要があるため、同じ x または y 軸プロットの 2 つのポイントがある場合にグラフのバグを修正できます。NSMutableArrays にはプリミティブ int が含まれています。私がしなければならないことの例は、4,8,5,3 などの軸の 1 つに 4 つの座標が与えられた場合、配列を 3,4,5,8 にソートする必要がある場合です。
以下のコードは非常に長いため、グラフ生成は含まれていません。
助けてくれてありがとう!-
int userInputCount;
printf("How many coordinates would you like to plot? ");
scanf("%i", &userInputCount);
printf("\n");
NSMutableArray * xCoordArray = [[NSMutableArray alloc] init];
NSMutableArray * yCoordArray = [[NSMutableArray alloc] init];
for (int i = 1; i <= userInputCount; i++){
int xCoord;
int yCoord;
printf("(%i) Enter coordinates [X,Y]: ", i);
scanf("%i,%i", &xCoord, &yCoord);
NSNumber *xCoordinate = [[NSNumber alloc] initWithInt:xCoord];
NSNumber *yCoordinate = [[NSNumber alloc] initWithInt:yCoord];
[xCoordArray addObject:xCoordinate];
[yCoordArray addObject:yCoordinate];
}