linked list

Posted on 2004-04-18
Last Modified: 2013-12-14
struct Data
   char name[51];
   int size;
   int num;
   char r[51];
   char a[51];
   char x[51];

The information is read from a file and stored in the structure using

I need help on how to store the information from the struct to a linked list.

Question by:aajjaa
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 12

Accepted Solution

stefan73 earned 50 total points
ID: 10857446
Hi aajjaa,
Use the list template of STL:

#include <list>
typedef list<Data> DataList;
DataList myDataList;

...and voilà, your data is in a linked list.


Author Comment

ID: 10864392
Thank you Stefan! that's exactly what I needed to know

Author Comment

ID: 10864651
Now that I have all the elements in my linked list, if I want to sort them by name.. I was wondering if it is better to use vectors instead of list?  I know there's a sort function for vectors, I'm not familiar with one for list. Can you please advice me on what to use?

With this data, I will also need to find a specific name, r, a, or etc in the list.. I'm planning in using the following code:
list<Data>::iterator iter;
{ //found }
{ //not found }

Is this OK?

LVL 12

Expert Comment

ID: 10877013
A linked list is not good for sorting or searching.

Maybe you should use a vector or a map, depending on whether you need sorting or fast search more often.
LVL 12

Expert Comment

ID: 10877018
Your iterator use is correct.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question