473,657 Members | 2,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem in Singly Linked List in C

144 New Member
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,D isplay

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
  1.  
  2. #include<stdio.h>
  3.  
  4. void create();
  5. void diaplay();
  6. void delete();
  7.  
  8.  
  9. struct node
  10. {
  11. int data;
  12. struct node *next;
  13. }
  14.  
  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);
  38.  
  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. }
  53.  
It will be really Helpful...Pl Help Me........

Thanks in Advance.
Apr 4 '09 #1
7 5731
weaknessforcats
9,208 Recognized Expert Moderator Expert
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
davidson1
144 New Member
Weak...

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

Linkedlist will be easy there?????
Apr 4 '09 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
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
donbock
2,426 Recognized Expert Top Contributor
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
sanddune008
4 New Member
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
sunny4063
2 New Member
[clip-clip]

Spoonfeeding removed per posting guidelines.

-weaknessforcats
Apr 9 '09 #7
donbock
2,426 Recognized Expert Top Contributor
@davidson1
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

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

Similar topics

4
4704
by: HS-MOON | last post by:
I'm asking you to help me. I'm a beginner of studying c++. I'm trying to make the Singly Linked List(Ordered). Anyway, I've been debugging all day. I can't sort it out!! As you see, I don't know what this is wrong.. When I run this pgm, It can't find the Current Variable. //
19
13566
by: RAJASEKHAR KONDABALA | last post by:
Hi, Does anybody know what the fastest way is to "search for a value in a singly-linked list from its tail" as oposed to its head? I am talking about a non-circular singly-linked list, i.e., head and tail are not connected. Of course, recursive function aproach to traverse the list is one way. But, depending upon the list size, it could overrun the stack pretty fast.
57
4269
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
7
1969
by: Shwetabh | last post by:
Hi, can some one tell me: -> how to remove a loop from a singly linked list with a loop. -> how to count the number of nodes in a looped singly link list. Thanks
59
4207
by: Anando | last post by:
Hi, I have a linear singly linked list of 100 elements. I would like to prune it such that only user specified elements (say only the elements 1, 13, 78 and 100 of the original list) survive after pruning. Can somebody show me how to do this ? I am a scientist and not a computer engineer/student. This will help me develop an application in data analysis. I will be grateful for your advice.
3
3412
by: jou00jou | last post by:
Hello, I am trying to sort a singly linked list for the following typedef typedef struct message { int messageId; char * messageText; struct message * next; } message; I have successfully implemented add, delete, print, and search functions for the linked list but I am not sure why I am stuck with this one.
23
4363
by: Himanshu Chauhan | last post by:
Hi! I was wondering, In the first parse of a singly linked list of unknown length, is it possible to know when we are at middle of the linked list? Regards --Himanshu
4
4306
by: saki | last post by:
How do we reverse a singly linked list without using extra memory.Extra pointers can however be used
6
391
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.