By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,917 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,917 IT Pros & Developers. It's quick & easy.

Problem in Singly Linked List in C

P: 144
Hello friends,

I want ur help regarding singly linked list in C,I tried in net,But it is confusing and difficult.I want singly linked list in a simple way of Understanding.Please Help Me

I want single list to create,delete,Display

Can u give me Program and Explanation,to create,display,Delete in a Simple and Easy Way.Really it will be Helpful for Me.

I have given some partial code,I want Program to create,display,Delete a Singly linked list....

Expand|Select|Wrap|Line Numbers
  2. #include<stdio.h>
  4. void create();
  5. void diaplay();
  6. void delete();
  9. struct node
  10. {
  11. int data;
  12. struct node *next;
  13. }
  15. void main()
  16. {
  17. do
  18. {
  19. int a;
  20. Printf("Choose Option\n");
  21. Printf("1.Create\n");
  22. printf("2.Display\n");
  23. printf("3.Delete\n");
  24. printf("Enter the Option")
  25. scanf("%d",&a);
  26. switch(a)
  27. {
  28. case 1:
  29. create();
  30. case 2:
  31. display();
  32. case 3:
  33. delete();
  34. default:
  35. printf("Thank U");
  36. }
  37. }while(a>3);
  39. void create()
  40. {
  41. //Can u give program and Explanation in a Simple Way
  42. }
  43. void display()
  44. {
  45. //Can u give program and Explanation in a Simple Way
  46. }
  47. void delete()
  48. {
  49. //Can u give program and Explanation in a Simple Way
  50. }
  51. getch();
  52. }
It will be really Helpful...Pl Help Me........

Thanks in Advance.
Apr 4 '09 #1
Share this Question
Share on Google+
7 Replies

Expert Mod 5K+
P: 9,197
Get yourself a copy of Teach Yourself Data Structures and Algorithms in 24 Hours by Robert LaFore.

The linked list is explained and code provided.
Apr 4 '09 #2

P: 144

Wheather I can download it from net...????...................

Linkedlist will be easy there?????
Apr 4 '09 #3

Expert Mod 5K+
P: 9,197
I have no idea if the book can be downloaded from the net. My copy is an actual book, like from a bookstore.

I have no doubt that a Google will bring up thousands of sources.

The book was only a suggestion. Personally, I have a library of about 20 books that I use all the time.
Apr 5 '09 #4

Expert 100+
P: 2,400
How simple and easy a singly linked list can be implemented depends on the real-world constraints of your problem. Algorithms that are perfectly acceptable for a list of a few hundred nodes are prohibitively slow for a list of a few million nodes.

What about your delete-node function? Do you prefer to identify the node to be deleted by the 'data' value within its node or by the address of the node itself? If the node is identified by its address, then that presupposes that the caller has some way to find the address of the desired node. That sounds like a search function is needed too. If the node is identified by its data, then you will need an implicit search function within your delete function.
Apr 6 '09 #5

P: 4
Hope this will help you......

[ snip ]

No spoonfeeding please; read the forum guides (see the 'help' link near the top right of this page).

kind regards,

Jos (moderator)
Apr 8 '09 #6

P: 2

Spoonfeeding removed per posting guidelines.

Apr 9 '09 #7

Expert 100+
P: 2,400
1. I assume that by "create a list" you mean two separate and independent functions: initialize a list to empty; and add a node to a list. Notice that I'm hinting at two different data types: a list and a list-node.

2. I assume that by "delete a list" you mean delete a node from a list.

3. I assume that by "display a list" you mean that you want to display the contents of the list in list-order. A more general way to phrase this is "traverse" -- a function that visits each node of the list. You could either hard-code your traverse function to display each node or you could pass it a function pointer argument so that a user function is called for each node.

4. Your sample code indicated that the only data information within the list nodes is a single int value. Is that all you need to support, or do your functions need to be flexible enough to handle more complicated data payloads?

5. Does your list need to be kept in some particular proper order as nodes are added?

6. Do prefer to have a static pool of free list nodes or would you rather malloc() the nodes when its time to add them to the list and free() them as you delete them from the list?

Haven't heard from you for awhile -- are you still curious about this question?
Apr 9 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.