Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- struct nodo{
- char info;
- nodo *succ;
- };
- using namespace std;
- void stampa(nodo *head){
- while(head->succ!=NULL){
- cout<<head->info<< " ";
- head=head->succ;
- }
- cout<<head->info;
- }
- void add(nodo *head,char n){
- if(head->succ==NULL){
- nodo *head1 = new nodo();
- head1->info=n;
- head1->succ=NULL;
- head->succ=head1;
- }else{
- add(head->succ,n);
- }
- }
- bool sottosequenza(nodo *head1,nodo *head2){
- if(!head1 && head2){
- return false;
- }
- if(!head2){
- return true;
- }
- if(head1->info==head2->info){
- return sottosequenza(head1->succ,head2->succ);
- }else{
- return sottosequenza(head1->succ,head2);
- }
- }
- int main(int argc, const char * argv[]) {
- nodo *head1 = new nodo();
- head1->info='B';
- add(head1,'F');
- add(head1,'C');
- add(head1,'A');
- add(head1,'F');
- add(head1,'P');
- add(head1,'9');
- add(head1,'E');
- add(head1,'8');
- nodo *head2 = new nodo();
- head2->info='P';
- add(head2,'9');
- add(head2,'E');
- add(head2,'8');
- stampa(head1);cout<<endl;
- stampa(head2);
- cout<<endl<<"head2 รจ sottosequenza di head1? "<<boolalpha<<sottosequenza(head1,head2)<<endl;
- cout<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment