Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class list{
- public:
- list *next;
- int n;
- list(int a=0){
- n=a;
- next=NULL;
- }
- void add(int a){
- list *current=this;
- while(current->next!=NULL)
- current=current->next;
- current->next=new list(a);
- }
- list *operator[](int a){
- list *current=this;
- for(int i=0;i<a;i++){
- if(current->next!=NULL)
- current=current->next;
- else break;
- }
- return current;
- }
- };
- int main(int argc, char **argv){
- list L(5);
- L.add(6);
- L.add(7);
- L.add(42);
- cout<<L[3]->n<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment