Archive

Posts Tagged ‘List’

Simple STL code in C++

February 11, 2009 Leave a comment

Just a general simple program for the Standard Template Library (STL) List

#include <list>
#include <iostream>
using namespace std;
////////////////////////////////
class codeWord{
public:
double vl[3];
double minI;

codeWord(){
minI = 0;
vl[0]=vl[1]=vl[2] = 0;
};
};
////////////////////////////////
void printList(std::list<codeWord *> &ml){
cout <<endl;

codeWord *ptr;
for(std::list<codeWord *>::iterator list_iter = ml.begin(); list_iter != ml.end(); list_iter++)    {
ptr = *list_iter;
std::cout<<” ” << ptr->minI<<endl;
}

cout <<endl;

};
////////////////////////////////
void main(void){

std::list<codeWord *> mlist;
codeWord a;
codeWord b;

a.minI = 10;
b.minI = 5;

mlist.push_front(&a);
mlist.push_front(&b);

printList(mlist);

};

Advertisements
Categories: STL Tags: ,