Advertisement
catalyn

problema cu stive

Jun 4th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. //creati doua stive cu nr din date.in astefel in prima stiva numerele rotunde in a doua in a doua restu si afisati-le continutul
  2. #include <iostream>
  3. #include<fstream>
  4. using namespace std;
  5.  
  6. struct stiva
  7. {
  8. int info;
  9. stiva *adr;
  10. };
  11. stiva *vfr, *vfo;
  12.  
  13. int rotund (int x)
  14. {
  15. while(x)
  16. {
  17. if(x%2==0)
  18. return 0;
  19. x=x/2;
  20. }
  21. return 1;
  22. }
  23.  
  24. void push(stiva *&vf, int x)
  25. {
  26. if(vf==NULL)
  27. {
  28. vf=new stiva;
  29. vf->adr=NULL;
  30. vf->info=x;
  31. }
  32. else
  33. {
  34. stiva *nou;
  35. nou=new stiva;
  36. nou->info=x;
  37. nou->adr=vf;
  38. vf=nou;
  39. }
  40. }
  41.  
  42. void creare()
  43. {
  44. int x;
  45. ifstream fin("date.in");
  46. while(fin>>x)
  47. if(rotund(x)==1)
  48. push(vfr,x);
  49. else
  50. push(vfo,x);
  51. }
  52.  
  53. void pop(stiva *&vf)
  54. {
  55. if(vf==NULL)
  56. return ;
  57. stiva *p;
  58. p=vf;
  59. cout<<vf->info<<" ";
  60. vf=vf->adr;
  61. delete p;
  62. }
  63.  
  64. int main()
  65. {
  66. creare();
  67. while(vfr!=NULL)
  68. pop(vfr);
  69. cout<<'\n';
  70. while(vfo!=NULL)
  71. pop(vfo);
  72. cout<<'\n';
  73.  
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement