c++ 垂直配列 垂直リストで出力を作成する方法。
何度も試してみましたが、うまくいきません。実行時に正確に印刷するにはどうすればよいですか? 印刷方法がわからないのでテストできません:/しかし、とにかく間違っているように感じます。サンプル出力は次のようになります
https://docs.google.com/file/d/0B5-VrB_qbetVX2xRQ2ZIYkxzQWc/edit?usp=sharing
#include <iostream>
#include <iomanip>
using namespace std;
#define SIZE 5
int* getData (int* pAry, int arySize);
void selectSort (int* pAry, int* pLast);
void printData (int* pAry, int* pLast);
int* smallest (int* pAry, int* pLast);
void exchange (int* current, int* smallest);
int main (void)
{
int ary[SIZE];
int* pLast;
pLast = getData (ary, SIZE);
selectSort (ary, pLast);
printData (ary, pLast);
return 0;
}
int* getData (int* pAry, int arySize)
{
int ioResult;
int readCnt = 0;
int* pFill = pAry;
do
{
cout<<"Enter Number Please: ";
ioResult = scanf("%d", pFill);
if (ioResult == 1)
{
pFill++;
readCnt++;
}
} while (ioResult == 1 && readCnt < arySize);
cout<<"\n\nOriginal: ";
for(int i = 0; i < SIZE; i++)
cout<<*pAry++;
return (--pFill);
}
void selectSort (int* pAry, int* pLast)
{
int* pWalker;
int* pSmallest;
for (pWalker = pAry; pWalker < pLast; pWalker++)
{
pSmallest = smallest (pWalker, pLast);
exchange (pWalker, pSmallest);
}
return;
}
int* smallest (int* pAry, int* pLast)
{
int* pLooker;
int* pSmallest;
for (pSmallest = pAry, pLooker = pAry + 1;
pLooker <= pLast;
pLooker++)
if (*pLooker < *pSmallest)
pSmallest = pLooker;
return pSmallest;
}
void exchange (int* current, int* smallest)
{
int temp;
//printf("This is the current value %d and this is the smallest value %d", *current, *smallest);
temp = *smallest;
*smallest = *current;
*current = temp;
return;
}
void printData (int* pAry, int* pLast)
{
int nmbrPrt;
int* pPrint;
cout<<"\n\nAscending:\t Descending ";
for (pPrint = pAry, nmbrPrt = 0;
pPrint <= pLast;
nmbrPrt++, pPrint++)
cout<<"\n"<<*pPrint<<"\n<";
for (pPrint = pLast, nmbrPrt = 0;
pPrint >= pAry;
nmbrPrt--, pPrint--)
{
cout<< *pPrint<<"\v";
}
cout<<"\n\nDone\n\n ";
return;
}
編集
do
{
cout<<"Enter how many times";
cin>>SIZE;
cout<<"Enter Number Please: ";
ioResult = scanf("%d", pFill);
if (ioResult == 1)
{
pFill++;
readCnt++;
}
} while (ioResult == 1 && readCnt < arySize);
これでどうだろう 2
int ary[SIZE];
int sary[SIZE];