Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- struct no
- {
- int info;
- no *esq, *dir;
- };
- typedef no* noptr;
- int criaLista(noptr &lista, int x)
- {
- if(lista != NULL)
- return 1;
- lista = new no;
- lista->info = x;
- lista->esq = NULL;
- lista->dir = NULL;
- return 0;
- }
- int inseredir(noptr &p, int x)
- {
- noptr q, d;
- if (p == NULL) // se p ´e NULL, n~ao d´a pra inserir `a direita
- return 1;
- else // inserindo n´o `a direita de p
- {
- q = new no;
- q->info = x;
- d = p->dir;
- d->esq = q;
- q->dir = d;
- q->esq = p;
- p->dir = q;
- return 0;
- }
- }
- int contanos(noptr &lista)
- {
- noptr t = NULL;
- int a = 0;
- for(t = lista; t != NULL; t = t->dir)
- {
- a++;
- }
- return a;
- }
- int somanos(noptr &lista)
- {
- noptr t = NULL;
- int soma = 0;
- for(t = lista; t != NULL; t = t->dir)
- {
- soma = soma + t->info;
- }
- return soma;
- }
- int main()
- {
- noptr lista = NULL;
- int val;
- cin >> val;
- while(val != 0)
- {
- if(lista == NULL)
- {
- criaLista(lista, val);
- }
- else
- {
- inseredir(lista, val);
- }
- cin >> val;
- }
- cout << "NUMERO DE ELEENTOS INSERIDOS: " << contanos(lista);
- cout << "SOMA: " << somanos(lista);
- cout << "MEDIA: " << somanos(lista)/(contanos(lista)*1.0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement