Advertisement
Denny707

20_06_2014_2 - buono

Jun 13th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. struct nodo{
  4. char info;
  5. nodo *succ;
  6. };
  7. using namespace std;
  8.  
  9. void stampa(nodo *head){
  10. while(head->succ!=NULL){
  11. cout<<head->info<< " ";
  12. head=head->succ;
  13. }
  14. cout<<head->info;
  15. }
  16.  
  17. void add(nodo *head,char n){
  18. if(head->succ==NULL){
  19. nodo *head1 = new nodo();
  20. head1->info=n;
  21. head1->succ=NULL;
  22. head->succ=head1;
  23. }else{
  24. add(head->succ,n);
  25. }
  26. }
  27.  
  28. bool sottosequenza(nodo *head1,nodo *head2){
  29. if(!head1 && head2){
  30. return false;
  31. }
  32. if(!head2){
  33. return true;
  34. }
  35. if(head1->info==head2->info){
  36. return sottosequenza(head1->succ,head2->succ);
  37. }else{
  38. return sottosequenza(head1->succ,head2);
  39. }
  40.  
  41. }
  42.  
  43. int main(int argc, const char * argv[]) {
  44. nodo *head1 = new nodo();
  45. head1->info='B';
  46. add(head1,'F');
  47. add(head1,'C');
  48. add(head1,'A');
  49. add(head1,'F');
  50. add(head1,'P');
  51. add(head1,'9');
  52. add(head1,'E');
  53. add(head1,'8');
  54.  
  55. nodo *head2 = new nodo();
  56. head2->info='P';
  57. add(head2,'9');
  58. add(head2,'E');
  59. add(head2,'8');
  60.  
  61. stampa(head1);cout<<endl;
  62. stampa(head2);
  63. cout<<endl<<"head2 รจ sottosequenza di head1? "<<boolalpha<<sottosequenza(head1,head2)<<endl;
  64. cout<<endl;
  65.  
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement