#include using namespace std; #define NOI(_arr) (sizeof(_arr)/sizeof(_arr[0])) class IHandler { public: IHandler *Next=0; virtual void HandleRequest(int data)=0; }; class ConcreateHandler : public IHandler { int id; public: int Limit; ConcreateHandler(int id, IHandler *handler):id(id) { Limit = id * 1000; Next = handler; } void HandleRequest(int data) { if (data < Limit) cout<<"Request for "<HandleRequest(data); else cout<<"Request for "< 0; i--) { cout<<"Handler "<HandleRequest(listOfData[i]); while(start){ IHandler *next = start->Next; delete start; start = (IHandler*)next; } return 0; } /* --------------------- OUTPUT ---------------------- Handler 5 deals up to a limit of 5000 Handler 4 deals up to a limit of 4000 Handler 3 deals up to a limit of 3000 Handler 2 deals up to a limit of 2000 Handler 1 deals up to a limit of 1000 Request for 50 handled at level 1 Request for 2000 handled at level 3 Request for 1500 handled at level 2 Request for 10000 handled BY DEFAULT at level 5 Request for 175 handled at level 1 Request for 4500 handled at level 5 ------------------------------------------------------*/