Solved

Linked list in c <list.h> ?

Posted on 2003-11-22
5
2,958 Views
Last Modified: 2013-12-14
Hi,
I want to use a linked list in c, and I saw that there's a file called list.h in the include of visual studio... Is that what I'm supposed to use? If so, can you please give me an example of how to do that?
Thanks,
Itsik
0
Comment
Question by:JavaInTheMorning
[X]
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
5 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9802706
If this is you home assignment, you need to write everything on your own ... you cannot use the list.h that is already there ... I think it is C++ lib file ... so you cannot use it for a C programming assignment any way
0
 
LVL 3

Author Comment

by:JavaInTheMorning
ID: 9802728
This is a home assignment, but the point is not using a linked list, this is something I want to do... THe point is drawing something with OpenGL... I found out about CList, can anyone give me an example of using it?

Thanks,
Itsik
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 9803203

#include <list.h>

// or new-style header:
// #include <list>
// using namespace std;

typedef list<int> INT_LIST;


INT_LIST list;

list.push_back(1);
list.push_back(2);
list.push_back(3);


INT_LIST::iterator theIterator;

for (theIterator = list.begin(); iterator != list.end(); theIterator++)
{
    printf("%d\n", *theIterator);
}

list.clear();

0
 
LVL 17

Expert Comment

by:rstaveley
ID: 9804296
If you want to use Microsoft's CList, check out the COLLECT example at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample/html/_sample_mfc_COLLECT.asp. Be warned that this is MFC, which means that it is non-standard C++ and should be discussed at http:/Programming/Programming_Languages/MFC/ .

AlexFM's suggestion to use the STL containers is standard C++ and should be discussed at http:/Programming/Programming_Languages/Cplusplus/ . If it is neither here nor there to you, I'd go with AlexFM's suggestion.

Poor old vanilla C doesn't have containers in its libraries and non-specific requests for help in implementing linked lists in C usually get followed up by accusations of homework cheating.... and quite rightly so :-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

691 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