Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been having some difficulties understanding Linked List. I have been trying to attempt a question on Anagram whereby the question asks to store the words in Linked List and generate the different anagrams from there.

I understand I need to produce permutations of the word. However, how do I store each and every word in the linked list? My understanding of the linked list is quite weak. Here's how I roughly imagine it to be:

What I have tried:

I store each letter in the word into each node of a singly linked list. Then I need to rearrange the nodes in different ways accordingly to the permutation. For example, CAR. The first node stores C, second stores A, and third node stores R. Now how do I instruct the nodes to arrange themselves in six (3!) different ways and output the results (Anagrams) ?

Is my thought process correct? Please bear with me as I am trying to understand this concept and also the coding part of it.
Posted
Updated 28-May-20 12:28pm
v2

In my opinion, the requirements are clear: store the words (not the letters) in the linked list.
 
Share this answer
 
Linked list is concept of processing data with software. Read this great explanation of Linked List in C++.

When you are allowed to use classes than use string class like std::string. It makes working with string a lot easier.
 
Share this answer
 
Quote:
I have been having some difficulties understanding Linked List.

To understand linked lists, you need to compare with array.
An array is very nice when static (allocated once at beginning), It allow direct access to a random element, but it is bad with add, remove or move element.
With a linked list, direct access to random element is not good, but is very good at add, remove or move element.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900