Solved

Linked list in c <list.h> ?

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

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

696 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