Reversing a linked list...

This is a discussion on Reversing a linked list... within the C Programming forums, part of the General Programming Boards category; Hi everyone, I have been handed an assignment that reads like this: "Write a program that reverses a linked list. ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    177

    Reversing a linked list...

    Hi everyone, I have been handed an assignment that reads like this:

    "Write a program that reverses a linked list. Include the following functions in your program: (1) the function to insert a node into the beginning of the linked list; (2) the function to remove the first node from the linked list. Start with creating a linked list (L1) containing integers: 5, 7, 9, 11, 13, 15 (where 5 is in the first node of the resulting list, and 15 is in the last node.) Then call the function to delete the first node from (L1) and another function to insert it in the beginning of another linked list (L2). Continue while your list (L1) is not empty."

    Can someone tell me how functions I will actually need and what they would do? I am not really understanding the question. I do not want anyone to write this for me, I just need some clarification. Thanks everyone!

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Well it sounds like you'll need to create 2 functions:

    (1) the function to insert a node into the beginning of the linked list

    (2) the function to remove the first node from the linked list

    The rest of the requirements just explain how/when to call those functions.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,296
    Those two functions have a body of really only one or two lines of code each.
    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"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 10:03 AM
  2. Replies: 5
    Last Post: 11-04-2006, 05:39 PM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 08:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21