How would I make a linked list of a linked list in C? For example I want a linked list that holds all the words inputted from the user. Example:
typedef struct node{
char *word;
struct node *next;
}node;
This list will hold all the strings that were inputted from the user.
What I want to do is have another linked list that holds all the words that are no vowel matches which means that they would be equal if we remove the vowels (non-case sensitive) in some sort of set. Like if the user inputs:
hat hit hoot hate test tast past pest
The output would be:
hat hit hoot HATE
test tast
past pest
Every line of words are equal if we remove the vowels from them. All of which are stored in a linked list of their own.
I know this is somewhat easy to do in other languages that have object oriented, but C is not, and I am barely starting to learn it so any help would be appreciated!
You can use another struct on top of the node struct and create a "list" linked list.
typedef struct node{
char *word;
struct node *next;
}node;
typedef struct list{
node* n;
int alphabet[26];
node* next;
}list;
I have not provided the code for the entire problem because I feel providing you with the clear logic of the process should be sufficient for you to program the code.
The logic for the separation of lists of strings based on your criteria is as follows
// listIterator was initialised as
// list* listIterator = (list*)malloc(sizeof(list))
// this acts as the general way to traverse the linked list called "list"
listIterator->next->next = (node*)malloc(sizeof(node))
listIterator->next->next->word = //the word you are parsing through
The process may seem a bit confusing but the ideas are very simple, you have a list inside a list, both of which are mutable and extendable.
Get Answers For Free
Most questions answered within 1 hours.