Thread: Stack using linked list

  1. #1
    Registered User
    Join Date
    Oct 2017
    Posts
    2

    Stack using linked list


  2. #2
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Thanks for that. I'll add it to my list of fundamental algorithms

    It's really fascinating watching someone type code

    a) Do not cast the return value of malloc()
    b) Preferably do not use sizeof(node) -- use sizeof (*temp)
    c) Functions should do one thing; not, for example, a function called push() should not be getting the value to push from the user
    d) Check the return value of scanf()
    e) If your function does not take any parameters then say so. Don't use void push(), use void push(void). This is C, not C++ and the two declarations have slightly different semantics. By the way push(), for example, *should* have a parameter (see item (c))
    f) <malloc.h> is a non-standard header; use <stdlib.h>

    Those are just the mistakes that jumped out. I'm not going to type in the program but are you sure it even works as intended?
    Last edited by Hodor; 10-26-2017 at 01:26 AM.

  3. #3
    Banned
    Join Date
    Aug 2017
    Posts
    861
    I didn't like the fact that while watching him/her type. as they moved down their piece of E-Paper. I couldn't scroll back up to check what had been written using my mouse wheel.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    From a guy who has to press compile TWICE to figure out that struct isn't spelled strcut.

    And to add to Hodor's list - global variables.

    Nothing to see folks.
    I'm done with this muppet posting mis-information.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack Linked List query
    By Josh Heathcote in forum C Programming
    Replies: 1
    Last Post: 03-10-2014, 11:31 PM
  2. stack using linked list problem
    By effa in forum C++ Programming
    Replies: 3
    Last Post: 09-18-2009, 12:10 PM
  3. STACK/FIFO as a linked list
    By BlackOps in forum C Programming
    Replies: 2
    Last Post: 07-24-2009, 02:04 PM
  4. Stack in linked list
    By mag_chan in forum C Programming
    Replies: 2
    Last Post: 11-09-2005, 05:31 AM
  5. linked list stack question
    By Drew in forum C++ Programming
    Replies: 2
    Last Post: 09-11-2003, 05:05 AM

Tags for this Thread