Solved

Linked list in c <list.h> ?

Posted on 2003-11-22
5
2,911 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
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 48

Expert Comment

by:AlexFM
ID: 9803216
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

757 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now