To tylko jedna z 2 stron tej notatki. Zaloguj się aby zobaczyć ten dokument.
Zobacz
całą notatkę
Struktura listowa
Visual C++ 6.0
#include
#include
#include
struct Item {
Item *pNext;
double value;
};
struct List {
Item *pFirst;
int count;
};
List list = { 0 };
int readData(char *fileName, List &list);
double getAverage(List &list);
double getResult(List &list, double average);
void freeMemory(List &list);
int main(int noOfArgs, char *pArg[])
{
if(noOfArgs != 2) {
cout tmp, tmp) {
Item *pItem = new Item;
pItem-pNext = list.pFirst;
pItem-value = tmp;
list.pFirst = pItem;
count++;
}
}
return list.count = count;
}
double getAverage(List &list)
{
double sum = 0;
Item *pItem = list.pFirst;
while(pItem) {
sum += pItem-value;
pItem = pItem-pNext;
}
return sum / list.count;
}
double getResult(List &list, double average)
{
double sumSqr = 0;
Item *pItem = list.pFirst;
while(pItem) {
double dif = pItem-value - average;
sumSqr += dif * dif;
pItem = pItem-pNext;
}
return sqrt(sumSqr) / list.count;
}
void freeMemory(List &list)
{
Item *pItem = list.pFirst, *pTmp;
while(pItem) {
(…)
… / list.count;
}
double getResult(List &list, double average)
{
double sumSqr = 0;
Item *pItem = list.pFirst;
while(pItem) {
double dif = pItem->value - average;
sumSqr += dif * dif;
pItem = pItem->pNext;
}
return sqrt(sumSqr) / list.count;
}
void freeMemory(List &list)
{
Item *pItem = list.pFirst, *pTmp;
while(pItem) {
pTmp = pItem->pNext;
delete pItem;
pItem = pTmp;
}
}
…
... zobacz całą notatkę
Komentarze użytkowników (0)