Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function somma_valori_campiinfosuccessivi(head,somma): int
- var head: nodo
- var somma: integer
- begin
- if(head!=NULL) then
- somma_valori_campiinfosuccessivi:=somma_valori_campiinfosuccessivi(head.link,somma+head.info)
- endif
- somma_valori_campiinfosuccessivi:=somma
- end
- function precedente_maggiore_sommasuccessivi(head): logical
- var head: nodo
- begin
- if(head!=NULL) then
- if (head.info>somma_valori_campiinfosuccessivi(head.link) then
- precedente_maggiore_sommasuccessivi:=precedente_maggiore_sommasuccessivi(head.link)
- else
- precedente_maggiore_sommasuccessivi:=false
- endif
- else
- precedente_maggiore_sommasuccessivi:=true
- endif
- end
- #include <iostream>
- using namespace std;
- struct nodo{
- int info;
- nodo *link;
- };
- void add(nodo* head,int info){
- if(head->link==NULL){
- nodo* N = new nodo;
- N->info=info;
- head->link=N;
- }else{
- add(head->link, info);
- }
- }
- void display(nodo* head){
- while(head){
- cout<<head->info<<" ";
- head=head->link;
- }
- cout<<endl;
- }
- int somma_valori_campiinfosuccessivi(nodo* head,int somma=0){
- if(head){
- return somma_valori_campiinfosuccessivi(head->link,somma+head->info);
- }
- return somma;
- }
- bool precedente_maggiore_sommasuccessivi(nodo* head){
- if(head){
- if(head->info>somma_valori_campiinfosuccessivi(head->link)){
- return precedente_maggiore_sommasuccessivi(head->link);
- }else{
- return false;
- }
- }else{
- return true;
- }
- }
- int main(int argc, const char * argv[]) {
- nodo* P1 = new nodo;
- P1->info=1000;
- P1->link=NULL;
- add(P1,100);
- add(P1,70);
- add(P1,20);
- add(P1,8);
- add(P1,1);
- display(P1);
- cout<<boolalpha<<precedente_maggiore_sommasuccessivi(P1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement