Question

How would I make a linked list of a linked list in C? For example I...

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!

Homework Answers

Answer #1

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

  1. The List struct has a field called alphabet[26], this acts as a dictionary of characters, if the number of characters present in a single word (minus the vowels a,e,i,o,u) are the same then the string will be equal to its peers.
  2. This alphabet array allows us to acheive exactly that. The array is essentially storing the frequencies of each of the 26 characters. The index 0 stores the frequency of a, 1 stores the frequency of b and so on.
  3. Parse through the string input provided by the user. Assume the string input is " hat hit hoot hate test tast past pest ", as you had mentioned.
  4. For each word (for example - hate), do the following
    1. Parse the word character by character and record the number of times a character appears (this will be akin to the alphabet array) and save this information in an array (let's call it temp)
    2. Now, use a while loop to go through the "list" linked list one by one and for e ach iteration check whether the alphabet array in the linked list item matched the temp array
    3. If the array matches (which can be done by checking each of the 21 elements, remember not checking for indices that correspond to vowels) then append this word to the "node" linked list inside this "list" linked list.
    4. For "hate" the array will be empty, except for indices 7 (corresponding to character h's frequency) and 19 (corresponding to character t's frequency)
    5. The above step may look like
      // 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
    6. If the array does not match any of the linked list's alphabet arrays, then we have to create a new linked list node and then store this word by creating another linked list inside this new one (for storing list of words, that is)

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C++ Goals  Build single linked lists using pointers  Learn how to manipulate linked lists...
C++ Goals  Build single linked lists using pointers  Learn how to manipulate linked lists In this lab, you will create simple single linked structures consisting of Node objects. Each node will have a pointer to the next node. You will use a head pointer to keep track of the first node in the linked list, and a tail pointer to keep track of the last node in the linked list. Set both head and tail to NULL when...
Java Generic Linked List Problem: How do I remove a slice of a linked list and...
Java Generic Linked List Problem: How do I remove a slice of a linked list and add its data to another linked list in java? Example: Private<T> head; Private int size; Public List<T> slice(int from, int to) { // This method will remove the data from the given range (inclusive) and add it to a new List and return this new list. }
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions are suggested for easier procedure of making function.) void search_node(struct linked_list* list, int find_node_ value) (The function to make) This function finds the node from the list that value is same with find_node_value and count the order of the node. This function should print message “The order of (node_value) is (order).” and error message “Function search_node : There is no such node to search.”....
(C++) Suppose you want to use a linked list where the items stored in the list...
(C++) Suppose you want to use a linked list where the items stored in the list are strings from the standard library string class, how would you change the node1.h header file? Header File: #ifndef MAIN_SAVITCH_NODE1_H #define MAIN_SAVITCH_NODE1_H #include <cstdlib> // Provides size_t and NULL namespace main_savitch_5 { class node { public: // TYPEDEF typedef double value_type; // CONSTRUCTOR node(const value_type& init_data=value_type( ), node* init_link=NULL) { data_field = init_data; link_field = init_link; } // MODIFICATION MEMBER FUNCTIONS node* link( )...
Using C++ / provide code comments so I can understand. Create a simple linked list program...
Using C++ / provide code comments so I can understand. Create a simple linked list program to create a class list containing class node { void *info; node *next; public: node (void *v) {info = v; next = 0; } void put_next (node *n) {next = n;} node *get_next ( ) {return next;} void *get_info ( ) {return info;} }; Be able to initially fill the list. Provide functions to insert/append nodes and remove nodes from the linked list. Be...
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
"C language" Take this code and make the minor modification necessary to create a circular linked...
"C language" Take this code and make the minor modification necessary to create a circular linked list (Hint: Store a pointer to the first node in the next pointer of the last node.) Demonstrate that this is working by traversing the list until the first pointer is encountered 3 times. Next redefine the node structure to include a back pointer. This will enable your program to move from front to back and then from back to front. It is not...
How would I make a generic insertion sort for a doubly linked list in java? or...
How would I make a generic insertion sort for a doubly linked list in java? or is it even possible to make it generic in the first place?
Adding large numbers with linked list Requirement - in C++ - use file for the input...
Adding large numbers with linked list Requirement - in C++ - use file for the input (nums.txt) - (recommended) use only one linked list to hold intermediate answer and final answer. You may use another one to reverse the answer. - store the num reversely in the linked list. For example, the num 123 is stored as 3 (at first node), 2 (at second node) and 1 (at third node) in the linked list. - write a function that performs...
I'm working with doubly linked lists in c++, I have written my classes and constructors. I...
I'm working with doubly linked lists in c++, I have written my classes and constructors. I need help with a randomizing method, any guidance or sample code would be appreciated, I'm pretty lost. For the method: void DLL::Random(); I want to basically shuffle/randomize my list. My list is a list of strings (names) if that's important to know. I'm mainly struggling with how to use pointers to prev and next to apply to each node and then move them throughout...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT