Thread: structs and linked lists

  1. #1
    Registered User
    Join Date
    Apr 2018
    Posts
    32

    structs and linked lists

    For an assignment I have to create a linked list.
    I have to read from an input file and save the contents to a linked list.
    But before that I want to ask for advice which approach would be wiser.
    The Input file looks something like this.
    Jake 21
    Mark 22
    King 34
    William 25 and so on.. in total I have 26 names with age.

    I have looked up linked lists.


    |data |217| | data |218| |data |NULL|




    So I have data with the adress of the next nodes.
    My guess is that for each nodes I store name and age.
    However I have 26 Names in the input file should I create 26 nodes?
    Would that make any sense or am I completely on the wrong track?

    I apologize if this is a stupid question, but I have been looking for tips on the internet for hours and I can't seem to find a sensible approach.



    I have just come up with a soloution ignore this post sry https://cboard.cprogramming.com/imag...lies/smile.png
    Last edited by Obvious Guy; 12-17-2018 at 03:09 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,078
    I hope that the solution you came up with involves:
    • A struct type to model the data consisting of name and age.
    • A struct type to model the node that contains the data struct and the next pointer
    • Especially if your linked list has both head and tail: a struct type to model the entire linked list
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structs and Linked Lists
    By ChickenChowMinh in forum C Programming
    Replies: 14
    Last Post: 10-03-2013, 01:50 AM
  2. Replies: 6
    Last Post: 10-24-2012, 10:05 AM
  3. with linked lists and structs
    By cable in forum C Programming
    Replies: 4
    Last Post: 10-10-2011, 08:11 PM
  4. Replies: 3
    Last Post: 01-22-2002, 12:22 AM
  5. file i/o-structs,linked lists
    By new2c in forum C++ Programming
    Replies: 3
    Last Post: 12-16-2001, 11:31 PM

Tags for this Thread