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
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
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....
"There's always another way"
-lightatdawn (lightatdawn.cprogramming.com)
Well how abt storing the ASCII value inside a node.... And when displaying it convert it back to char.. THis is more preferable..
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*