LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 08-19-2005, 06:11 AM   #1
ssg14j
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, 07:25 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

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

Quote:
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, 07:54 AM   #3
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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, 07:56 AM   #4
NCC-1701&NCC-1701-D
Member
 
Registered: May 2005
Distribution: Debian Woody,Knoppix
Posts: 88

Rep: Reputation: 16
http://cslibrary.stanford.edu/103/

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

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


Reply


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 11:15 AM
linked list + c dilberim82 Programming 5 05-05-2005 12:48 AM
C program problem on delete duplicated nodes in linked list ! antony_csf Programming 2 10-28-2004 11:42 AM
imple,menting a linked list in c program in linux bprasanth_20 Programming 17 10-25-2003 03:06 AM
C++ linked list fun chens_83 Programming 2 08-04-2003 08:40 AM


All times are GMT -5. The time now is 04:32 AM.

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