Thread: Delettion of node in singly linked list

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    2

    Arrow Delettion of node in singly linked list

    Please help me in inserting delete function it

    Code:
    #include<stdio.h>
    #include<malloc.h>
    
    struct node
    {
         int data;
         struct node *next;
    }*start;
    
    int insert(int num)
    {
         struct node *a;
         a=(struct node*)malloc(sizeof(struct node));
         a->data=num;
         a->next=start;
         a=start;
    }
    
    int display()
    {
        while(start->next!=NULL)
        {
             printf("%d",start->data);
         }
    }
    
    main()
    {
       start=NULL;
       insert(20);insert(30);insert(40);
       display;
    }

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    do you have a code that compiles?
    1. Fix compilation errors in the current code
    2. fix logical errors - so the program works and does whot it should
    3. Only after that start adding new functionality
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    58
    Code:
    a=start;
    should be

    Code:
    start=a;
    and:

    Code:
    display;
    should be

    Code:
    display();

    besides, there's no malloc.h library, malloc is in stdlib.h

  4. #4
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Quote Originally Posted by Govalant View Post
    besides, there's no malloc.h library, malloc is in stdlib.h
    There used to be, but it's deprecated now.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  5. #5
    Registered User
    Join Date
    May 2007
    Posts
    58
    Quote Originally Posted by Happy_Reaper View Post
    There used to be, but it's deprecated now.
    oh ok

  6. #6
    Registered User
    Join Date
    Jun 2007
    Posts
    2
    yeh i hav compiled it separately but plz tell me the code for deletion in this.How i insert

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by gamer_trex29 View Post
    yeh i hav compiled it separately but plz tell me the code for deletion in this.How i insert
    Please do not do as this poster says.
    He is not asking for help, he is clearly only asking for the answer to homework.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    yeh i hav compiled it separately
    Then - show the code you "hav compiled". And I mean - not just tried to - but succesfully finished with 0 errors and 0 warnings
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need urgent help in linked list
    By Cassandra in forum C++ Programming
    Replies: 4
    Last Post: 03-12-2009, 07:47 PM
  2. linked list question
    By brb9412 in forum C Programming
    Replies: 16
    Last Post: 01-04-2009, 04:05 PM
  3. Replies: 7
    Last Post: 06-16-2006, 09:23 PM
  4. Problems with deleting a node in a singly linked list
    By omishompi in forum C++ Programming
    Replies: 7
    Last Post: 02-23-2006, 06:27 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM