Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,561 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,633 people online right now. Registration is fast and FREE... Join Now!




how to implement list & set in C++?

 
Reply to this topicStart new topic

how to implement list & set in C++?, Linear Data Structures

eigeryap
27 Oct, 2007 - 08:34 PM
Post #1

New D.I.C Head
*

Joined: 21 Oct, 2007
Posts: 2


My Contributions
hello All.
Linear Structured Data types divided into list, set, stack & queue.
Now, i want to ask is, how to implement list & set in C++??
Can we use searching in queue??
Thanks. wink2.gif
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: How To Implement List & Set In C++?
27 Oct, 2007 - 09:25 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Simple, you can create a list and set as part of the STL containers list<type> and set<type>. Just like stacks and queues, they hold elements where the elements are the keys. Below is an example of setting up a list and adding to it...

CODE

#include <iostream>
#include <list>
using namespace std;


int main() {

    // Create a list of ints
    list<int> mylist;

    // Assign two elements of the value "10"
    mylist.assign(2,10);

    // Print out the size
    cout << "Size of mylist is: " << mylist.size() << endl;
    return 0;
}


A set is very similar but instead of assign it uses insert(). Just lookup the set and list container types to find all the methods available and such.

Enjoy!

"At DIC we be scare looking code wizards!" wizard.gif
User is offlineProfile CardPM
+Quote Post

Louisda16th
RE: How To Implement List & Set In C++?
27 Oct, 2007 - 10:26 PM
Post #3

 101010101
Group Icon

Joined: 3 Aug, 2006
Posts: 1,812



Thanked: 1 times
Dream Kudos: 755
My Contributions
QUOTE
"At DIC we be scare looking code wizards!"

How do you come up with all this tongue.gif?
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: How To Implement List & Set In C++?
28 Oct, 2007 - 12:38 AM
Post #4

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
QUOTE
How do you come up with all this tongue.gif?

too many nights in the barren great white north...there are times when i know exactly how he feels

This post has been edited by jjhaag: 28 Oct, 2007 - 01:07 AM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 10:11PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month