I just wanted to know where i can apply the concept of linked lists, or what kind of program requires linked lists application. If any body can help me, I will appreciate.
I just wanted to know where i can apply the concept of linked lists, or what kind of program requires linked lists application. If any body can help me, I will appreciate.
I use them almost whenever I cannot anticipate how big my data is going to grow. They are especially convenient when my elements can be of variable size. I nest them pretty deeply and bizarrely when am coding graftals. The coming of STL has made them almost as easy as a regular-old data type. Vector is a type that is internally dynamic, but allows for integer indexing. This allows for the ease of an array for a linked type. I use doubly-linked ones if my traversals are as likely to be backward as forward.
Don Hersey wrote:
I use them almost whenever I cannot anticipate how big my data is going to grow. They are especially convenient when my elements can be of variable size. I nest them pretty deeply and bizarrely when am coding graftals. The coming of STL has made them almost as easy as a regular-old data type. Vector is a type that is internally dynamic, but allows for integer indexing. This allows for the ease of an array for a linked type. I use doubly-linked ones if my traversals are as likely to be backward as forward.
I may have misunderstood you, but in case I didn't: std::vector is not implemented as a linked list. The reason you get to access it just as an array, is because that's exactly what it is (or more precisely what it is an interface for).
Don Hersey wrote:
I use them almost whenever I cannot anticipate how big my data is going to grow. They are especially convenient when my elements can be of variable size. I nest them pretty deeply and bizarrely when am coding graftals. The coming of STL has made them almost as easy as a regular-old data type. Vector is a type that is internally dynamic, but allows for integer indexing. This allows for the ease of an array for a linked type. I use doubly-linked ones if my traversals are as likely to be backward as forward.
I may have misunderstood you, but in case I didn't: std::vector is not implemented as a linked list. The reason you get to access it just as an array, is because that's exactly what it is (or more precisely what it is an interface for).
It interfaces like an array, but AFIK it is implemented internally as a list.
This is what allows for vector::resize.
In the case of std::vector, resize() will re-allocate (edit: if necessary) a new block of memory, big enough to hold the entire data and then relocate all the elements in there, in consecutive order.
Edit 2: If you don't believe me, try this:
vector<char> v;
v.push_back('h');
v.push_back('e');
v.push_back('l');
v.push_back('l');
v.push_back('o');
v.push_back('!');
v.push_back(0);
cout << &v[0] << endl;