Advertisement
Denny707

es_3

Jun 13th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. function somma_valori_campiinfosuccessivi(head,somma): int
  2. var head: nodo
  3. var somma: integer
  4. begin
  5. if(head!=NULL) then
  6. somma_valori_campiinfosuccessivi:=somma_valori_campiinfosuccessivi(head.link,somma+head.info)
  7. endif
  8. somma_valori_campiinfosuccessivi:=somma
  9. end
  10.  
  11. function precedente_maggiore_sommasuccessivi(head): logical
  12. var head: nodo
  13. begin
  14. if(head!=NULL) then
  15. if (head.info>somma_valori_campiinfosuccessivi(head.link) then
  16. precedente_maggiore_sommasuccessivi:=precedente_maggiore_sommasuccessivi(head.link)
  17. else
  18. precedente_maggiore_sommasuccessivi:=false
  19. endif
  20. else
  21. precedente_maggiore_sommasuccessivi:=true
  22. endif
  23. end
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. #include <iostream>
  31. using namespace std;
  32. struct nodo{
  33. int info;
  34. nodo *link;
  35. };
  36.  
  37. void add(nodo* head,int info){
  38. if(head->link==NULL){
  39. nodo* N = new nodo;
  40. N->info=info;
  41. head->link=N;
  42. }else{
  43. add(head->link, info);
  44. }
  45. }
  46. void display(nodo* head){
  47. while(head){
  48. cout<<head->info<<" ";
  49. head=head->link;
  50. }
  51. cout<<endl;
  52. }
  53. int somma_valori_campiinfosuccessivi(nodo* head,int somma=0){
  54. if(head){
  55. return somma_valori_campiinfosuccessivi(head->link,somma+head->info);
  56. }
  57. return somma;
  58. }
  59. bool precedente_maggiore_sommasuccessivi(nodo* head){
  60. if(head){
  61. if(head->info>somma_valori_campiinfosuccessivi(head->link)){
  62. return precedente_maggiore_sommasuccessivi(head->link);
  63. }else{
  64. return false;
  65. }
  66. }else{
  67. return true;
  68. }
  69. }
  70.  
  71.  
  72.  
  73. int main(int argc, const char * argv[]) {
  74. nodo* P1 = new nodo;
  75. P1->info=1000;
  76. P1->link=NULL;
  77. add(P1,100);
  78. add(P1,70);
  79. add(P1,20);
  80. add(P1,8);
  81. add(P1,1);
  82. display(P1);
  83. cout<<boolalpha<<precedente_maggiore_sommasuccessivi(P1);
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement