Struktura listowa - omówienie

Nasza ocena:

3
Pobrań: 7
Wyświetleń: 791
Komentarze: 0
Notatek.pl

Pobierz ten dokument za darmo

Podgląd dokumentu
Struktura listowa - omówienie  - strona 1 Struktura listowa - omówienie  - strona 2

Fragment notatki:

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)

Zaloguj się, aby dodać komentarz