I'm very use to working with arrays and vectors, but now I'm playing with some STD::lists, as well as a custom list class I made.
Let's say I have a simple class, Stock.
//stock.h
class Stock{
public:
Stock(); //default constructor
Stock(string, double); //overloaded constructor
void setSymbol(string); //sets stock symbol
void setPrice(double);
string getSymbol();
double getPrice();
private:
string symbol;
double price;
};
Now in a separate file I have my int main to test.
#include "stock.h"
#include <list>
int main(){
list<Stock> portfolio;
Stock Google("GOOG", 500);
Stock Apple("APPL", 300);
Stock Chipotle("CMG", 200);
portfolio.push_back(Google);
portfolio.push_back(Apple);
portfolio.push_back(Chipotle);
}
Now if this was a vector or array, I would have no problem, I'm just completely loss on the linked-list equivalent of the following:
for(int i=0; i <portfolio.size(); i++){
portfolio[i].getSymbol();
portfolio[i].getPrice();
}
Or something along those lines...I have no lecture/training in Linked-Lists so I'm really trying to do my best in teaching myself--but I'm stuck on basic manipulation. I'm using STL::list right now, but really trying to make my own class as well.
iterator. Unfortunately I'm too lazy to tell you how right now, but look it up!