Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3.  
  4. using namespace std;
  5.  
  6. struct jazol{
  7. int info;
  8. jazol* next;
  9. jazol* prev;
  10. };
  11. struct dplista{
  12. jazol* head;
  13. jazol* tail;
  14. void init();
  15. void dodadiPrv(int el);
  16. void dodadiPosleden(int el);
  17. void brishiPrv();
  18. void brishiPosleden();
  19. void brishiLista();
  20. };
  21. void dplista::init(){
  22. head=tail=NULL;
  23. }
  24. void dplista::dodadiPrv(int el){
  25. jazol *pom=new jazol;
  26. pom->info=el;
  27. pom->next=head;
  28. pom->prev=NULL;
  29. head=pom;
  30. if(head->next==NULL)
  31. tail=head;
  32. }
  33. void dplista::dodadiPosleden(int el){
  34. jazol* pom=new jazol;
  35. pom->info=el;
  36. pom->next==NULL;
  37. if(head==NULL){
  38. pom->prev=NULL;
  39. tail=head=pom;
  40. }
  41. else{
  42. pom->prev=tail;
  43. tail->next=pom;
  44. tail=pom;
  45. }
  46. }
  47. void dplista::brishiPrv(){
  48. if(head!=NULL){
  49. if(head->next==NULL){
  50. delete head;
  51. head=tail=NULL;
  52. }
  53. else{
  54. jazol* pom=head;
  55. head=head->next;
  56. head->prev=NULL;
  57. delete pom;
  58. }
  59. }
  60. }
  61. void dplista::brishiPosleden(){
  62. if(head!=NULL){
  63. if(head->next==NULL){
  64. delete head;
  65. head=tail=NULL;
  66. }
  67. else{
  68. jazol* pom=tail;
  69. tail=tail->prev;
  70. tail->next=NULL;
  71. delete pom;
  72. }
  73. }
  74. }
  75. void dplista::brishiLista(){
  76. while(head!=NULL)
  77. brishiPrv();
  78. }
  79. int main(){
  80. dplista l1,l2,l3;
  81. l1.init();
  82. l2.init();
  83. l3.init();
  84. int el;
  85. cout<<"Vnesi 10 elementi vo prvata lista\n"<<endl;
  86. for(int i=0;i<10;i++){
  87. cin>>el;
  88. l1.dodadi(el);
  89. }
  90. cout<<"Vnesi 10 elementi vo vtorata lista\n"<<endl;
  91. for(i=0;i<10;i++){
  92. cin>>el;
  93. l2.dodadi(el);
  94. }
  95. jazol* dvizi=l1.head;
  96. int pom=0;
  97. while(dvizi!=NULL){
  98. if(pom%2==0){
  99. l3.dodadiPosleden(dvizi->info);
  100. pom++;
  101. dvizi=dvizi->next;
  102. }
  103. pom=1;
  104. dvizi=l2.head->next;
  105. }
  106. return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement