Регистрация | Вход
#include <stdio.h>#include <stdlib.h>class CTwoDirList{public: CTwoDirList(CTwoDirList *pr); int number; ~CTwoDirList(); CTwoDirList* Next; CTwoDirList* Prev;};CTwoDirList::CTwoDirList(CTwoDirList *pr){ Next=NULL; Prev=pr; number=0;};CTwoDirList::~CTwoDirList(){ Prev->Next=Next; Next->rev=Prev;};void main(){ CTwoDirList *List,*temp,*temp1,*temp2; List= new CTwoDirList(NULL); List->number=10; temp=List; for (int i=0;i < 10;i++) { temp->Next=new CTwoDirList(temp); temp=temp->Next; temp->number=i; }; temp=List; printf("\nList in -> direction:"); while (temp!=NULL) { printf(" %d ",temp->number); if (temp->Next==NULL) temp1=temp; temp=temp->Next; }; printf("\nList in <- direction:"); temp2=temp1; while (temp1!=NULL) { printf(" %d ",temp1->number); temp1=temp1->rev; }; while (List!=NULL) { temp=List; List=List->Next; delete temp; };};