Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-19-2005, 05:11 AM   #1
LQ Newbie
Registered: Jul 2005
Posts: 12

Rep: Reputation: 0
concepts a linked list program in c

Tell me the concepts of Linked List program using c.......
Give me one example..
Old 08-19-2005, 06:25 AM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Re: concepts a linked list program in c

Originally posted by ssg14j
Tell me the concepts of Linked List program using c.......
Give me one example..
Why? Didn't google take orders from you?
Old 08-19-2005, 06:54 AM   #3
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
The concept is pretty simple. Define a struct for your link list node. A node comprises of data, which can be anything, and a pointer to another node typically called next.

When creating a link list node initially you want to set the next pointer to null and the data pointer to whatever you want it to be. The first node is typically called head, and you never want to have a situation where you don't have a pointer to this node anymore. I also like to always have a pointer to the end of the list I call tail. When creating the first node of a linked list I set both the head and tail pointer to it.

Say N1 is a pointer to a node.

N1->next = null;
head = N1;
tail= N1;

Now... to add a node to the beginning of the list you simply create the node, set the new node->next = head, and then set head = node;

N2->next = head;
head = N2;
our list now: head (aka N2)->next = tail( aka N1)->next = NULL

To add a node to the end of the list create the node, set tail->next equal to the node and move the tail pointer.

N3->next = NULL;
tail->next = N3;
tail = N3;
our list now: head (aka N2)->next = N1->next = tail (aka N3)->next = NULL;

I'll leave the rest as an exercise for the reader.
Old 08-19-2005, 06:56 AM   #4
Registered: May 2005
Distribution: Debian Woody,Knoppix
Posts: 88

Rep: Reputation: 16

Everything about linked lists in C (and in C++)
Hope it helped!
Old 08-19-2005, 10:10 AM   #5
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
This is so obviously homework...


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Linked List question lowpro2k3 Programming 3 06-16-2005 10:15 AM
linked list + c dilberim82 Programming 5 05-04-2005 11:48 PM
C program problem on delete duplicated nodes in linked list ! antony_csf Programming 2 10-28-2004 10:42 AM
imple,menting a linked list in c program in linux bprasanth_20 Programming 17 10-25-2003 02:06 AM
C++ linked list fun chens_83 Programming 2 08-04-2003 07:40 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:36 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration