I want to learn STL feature in C++. I have gone through "list" and its function like push_front(),pu sh_back() etc...
Now I want to ask , can I use "list" in my user defined class linkedlist ??
In other words I want to say , if I have been given to reverse the linked list, I will create and print it by STL ( using push_front() and copy ) and main reversing logic , I will do by class linkedlist which I defined so that I will save time to create linkedlist.
It means Can I use STL with User defined class ??
I tried it through following code.
Inserting node at the start of linked list
above code is not giving any output.
Can anybody help me ???
Now I want to ask , can I use "list" in my user defined class linkedlist ??
In other words I want to say , if I have been given to reverse the linked list, I will create and print it by STL ( using push_front() and copy ) and main reversing logic , I will do by class linkedlist which I defined so that I will save time to create linkedlist.
It means Can I use STL with User defined class ??
I tried it through following code.
Inserting node at the start of linked list
Code:
#include "stdafx.h" #include<iostream> #include<iterator> #include<conio.h> #include<list> #include<algorithm> using namespace ::std; struct link { int data; //data item link* next; // pointer to link }; class linklist //list of links { link* head; public: linklist() { head = NULL; } void additem(int d) { link* temp = new link; // make a new link temp->data = d; // give it data temp->next = head; head = temp; } }; int main() { linklist l1; list<int> l; // l to be list container ostream_iterator<int>screen(cout, " "); l1.additem(1); l1.additem(2); l1.additem(3); copy(l.begin(), l.end(), screen); cout << endl; _getch(); return 0; }
Can anybody help me ???
Comment