Advertisement
Guest User

prob

a guest
Oct 31st, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.79 KB | None | 0 0
  1. Tema Saptamanii #4
  2.  
  3. Obligatorii
  4.  
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. struct nod{
  10.     int info;
  11.     nod *urm;
  12. };
  13. nod *prim=NULL, *ultim;
  14.  
  15. void push(int x, nod *&prim){
  16.     nod *p=new nod;
  17.     if(prim==NULL){
  18.         p->urm=NULL;
  19.         p->info=x;
  20.         prim=p;
  21.         ultim=p;
  22.     }
  23.     else{
  24.         p->info=x;
  25.         p->urm=NULL;
  26.         ultim->urm=p;
  27.         ultim=p;
  28.  
  29.  
  30.     }
  31. }
  32.  
  33. void afis(){
  34.     nod *p;
  35.     for(p=prim;p!=NULL;p=p->urm)
  36.         cout<<p->info<<" ";
  37.     cout<<endl;
  38. }
  39.  
  40. int pop(nod *&prim){
  41.     nod *p;
  42.     p=prim;
  43.     int temp=p->info;
  44.     prim=prim->urm;
  45.     delete p;
  46.     return temp;
  47. }
  48.  
  49. bool eempty(nod *&prim){
  50.     if(prim==NULL)
  51.     return true;
  52.     else
  53.         return false;
  54. }
  55.  
  56. int peek(nod *&prim){
  57.     return prim->info;
  58. }
  59.  
  60. int ssearch(int a, nod *&prim){
  61.     int c=0,temp=-1;
  62.     for(nod *p=prim;p!=NULL;p=p->urm){
  63.         if(a==p->info)
  64.             temp=c;
  65.         c++;
  66.     }
  67.  
  68.     if(temp==-1)
  69.         return -1;
  70.     else
  71.         return temp;
  72.  
  73. }
  74.  
  75. int main()
  76. {
  77.     nod *p=new nod;
  78.     prim=NULL;
  79.     push(1,prim);
  80.     push(5,prim);
  81.     push(6,prim);
  82.     push(8,prim);
  83.     push(34,prim);
  84.     push(12,prim);
  85.     afis();
  86.     cout<<ssearch(1,prim);
  87.  /*   cout<<pop(prim)<<endl;
  88.     if(eempty(prim))
  89.         cout<<"Stiva e vida";
  90.     else
  91.         cout<<"Stiva nu e vida";
  92.     cout<<peek(prim)<<endl;
  93.     afis();*/
  94.     return 0;
  95. }
  96.  
  97. *******************************
  98. ???
  99.  
  100. #include <iostream>
  101.  
  102. using namespace std;
  103.  
  104. struct nod{
  105.     int info;
  106.     nod *urm;
  107. };
  108. nod *prim=NULL, *ultim;
  109.  
  110. void push(int x, nod *&prim){
  111.     nod *p=new nod;
  112.     if(prim==NULL){
  113.         p->urm=NULL;
  114.         p->info=x;
  115.         prim=p;
  116.     }
  117.     else{
  118.         p->info=x;
  119.         p->urm=prim;
  120.         prim=p;
  121.  
  122.     }
  123. }
  124.  
  125. int ssearch(int a, nod *&prim){
  126.     int c=0,temp=-1;
  127.     for(nod *p=prim;p!=NULL;p=p->urm){
  128.         if(a==p->info)
  129.             temp=c;
  130.         c++;
  131.     }
  132.  
  133.     if(temp==-1)
  134.         return -1;
  135.     else
  136.         cout<<temp<<endl;
  137.         return temp;
  138.  
  139. }
  140.  
  141. void afis(){
  142.     nod *p;
  143.     for(p=prim;p!=NULL;p=p->urm){
  144.         if(p->info==1)
  145.             cout<<"a ";
  146.         else
  147.             cout<<"b ";
  148.     }
  149.     cout<<endl;
  150. }
  151.  
  152. int pop(nod *&prim){
  153.     nod *p;
  154.     p=prim;
  155.     int temp=p->info;
  156.     prim=prim->urm;
  157.     delete p;
  158.     return temp;
  159. }
  160.  
  161. bool eempty(nod *&prim){
  162.     if(prim==NULL)
  163.     return true;
  164.     else
  165.         return false;
  166. }
  167. int peek(nod *&prim){
  168.     return prim->info;
  169. }
  170. int main()
  171. {
  172.     nod *p=new nod;
  173.     int n;
  174.     char l;
  175.     cout<<"n=";
  176.     cin>>n;
  177.     for(int i=0;i<n;i++){
  178.         cin>>l;
  179.         if(l=='a' && ssearch(0,prim)!=0)
  180.             push(1,prim);
  181.         if(l=='b')
  182.             push(0,prim);
  183.     }
  184.  
  185.     afis();
  186.     return 0;
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement