Problem in Singly Linked List in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • davidson1
    New Member
    • Feb 2008
    • 144

    Problem in Singly Linked List in C

    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....

    Code:
    #include<stdio.h>
    
    void create();
    void diaplay();
    void delete();
    
    
    struct node
    {
    int data;
    struct node *next;
    }
    
    void main()
    {
    do
    {
    int a;
    Printf("Choose Option\n");
    Printf("1.Create\n");
    printf("2.Display\n");
    printf("3.Delete\n");
    printf("Enter the Option")
    scanf("%d",&a);
    switch(a)
    {
    case 1:
    create();
    case 2:
    display();
    case 3:
    delete();
    default:
    printf("Thank U");
    }
    }while(a>3);
    
    void create()
    {
    //Can u give program and Explanation in a Simple Way
    }
    void display()
    {
    //Can u give program and Explanation in a Simple Way
    }
    void delete()
    {
    //Can u give program and Explanation in a Simple Way
    }
    getch();
    }
    It will be really Helpful...Pl Help Me........

    Thanks in Advance.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    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.

    Comment

    • davidson1
      New Member
      • Feb 2008
      • 144

      #3
      Weak...

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

      Linkedlist will be easy there?????

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        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.

        Comment

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          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.

          Comment

          • sanddune008
            New Member
            • Nov 2006
            • 4

            #6
            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)

            Comment

            • sunny4063
              New Member
              • Apr 2009
              • 2

              #7
              linked list code

              [clip-clip]

              Spoonfeeding removed per posting guidelines.

              -weaknessforcats

              Comment

              • donbock
                Recognized Expert Top Contributor
                • Mar 2008
                • 2427

                #8
                Originally posted by davidson1
                I want Program to create,display, Delete a Singly linked list....
                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?

                Comment

                Working...