How to start this linked list?

This is a discussion on How to start this linked list? within the C++ Programming forums, part of the General Programming Boards category; Hello, I am looking for some ideas on how to start making a program which makes a linked list of ...

  1. #1
    Registered User Daniel's Avatar
    Join Date
    Jan 2003
    Posts
    47

    How to start this linked list?

    Hello,

    I am looking for some ideas on how to start making a program which makes a linked list of characters? In other words I am remaking a string

    Thanks for your help,
    Daniel

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    ok....

    well, you could start by making a node struct that would hold a character and a pointer to the next one. (that would be the basis of the "linked list" part) although im not entirely sure why you would want to do this....

  3. #3
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  4. #4
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Well how abt storing the ASCII value inside a node.... And when displaying it convert it back to char.. THis is more preferable..

  5. #5
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    This is a good start :-)
    Code:
    #include <iostream>
    
    using namespace std;
    
    struct node {
      char token;
      node *next;
    
      node(char init, node *link): token(init), next(link){}
    };
    
    int main()
    {
      node *head, *np, *forward;
      const char s[] = "abcdefghijklmnopqrstuvwxyz";
    
      head = new node(0, 0); // Dummy head
      np = head;
    
      for (int i = 0; s[i] != '\0'; i++)
      {
        np->next = new node(s[i], 0);
        np = np->next;
      }
    
      for (np = head->next; np != 0; np = forward)
      {
        forward = np->next;
        cout<< np->token <<flush;
        delete np;
      }
    }
    *Cela*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  2. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  3. Help with linked list
    By GaPe in forum C Programming
    Replies: 43
    Last Post: 02-09-2002, 02:28 PM
  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