Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- struct jazol{
- int info;
- jazol* next;
- jazol* prev;
- };
- struct dplista{
- jazol* head;
- jazol* tail;
- void init();
- void dodadiPrv(int el);
- void dodadiPosleden(int el);
- void brishiPrv();
- void brishiPosleden();
- void brishiLista();
- };
- void dplista::init(){
- head=tail=NULL;
- }
- void dplista::dodadiPrv(int el){
- jazol *pom=new jazol;
- pom->info=el;
- pom->next=head;
- pom->prev=NULL;
- head=pom;
- if(head->next==NULL)
- tail=head;
- }
- void dplista::dodadiPosleden(int el){
- jazol* pom=new jazol;
- pom->info=el;
- pom->next==NULL;
- if(head==NULL){
- pom->prev=NULL;
- tail=head=pom;
- }
- else{
- pom->prev=tail;
- tail->next=pom;
- tail=pom;
- }
- }
- void dplista::brishiPrv(){
- if(head!=NULL){
- if(head->next==NULL){
- delete head;
- head=tail=NULL;
- }
- else{
- jazol* pom=head;
- head=head->next;
- head->prev=NULL;
- delete pom;
- }
- }
- }
- void dplista::brishiPosleden(){
- if(head!=NULL){
- if(head->next==NULL){
- delete head;
- head=tail=NULL;
- }
- else{
- jazol* pom=tail;
- tail=tail->prev;
- tail->next=NULL;
- delete pom;
- }
- }
- }
- void dplista::brishiLista(){
- while(head!=NULL)
- brishiPrv();
- }
- int main(){
- dplista l1,l2,l3;
- l1.init();
- l2.init();
- l3.init();
- int el;
- cout<<"Vnesi 10 elementi vo prvata lista\n"<<endl;
- for(int i=0;i<10;i++){
- cin>>el;
- l1.dodadi(el);
- }
- cout<<"Vnesi 10 elementi vo vtorata lista\n"<<endl;
- for(i=0;i<10;i++){
- cin>>el;
- l2.dodadi(el);
- }
- jazol* dvizi=l1.head;
- int pom=0;
- while(dvizi!=NULL){
- if(pom%2==0){
- l3.dodadiPosleden(dvizi->info);
- pom++;
- dvizi=dvizi->next;
- }
- pom=1;
- dvizi=l2.head->next;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement