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...
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 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...
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...
How would I go about implementing a function in C++ that swaps the front node and...
How would I go about implementing a function in C++ that swaps the front node and tNode with each other in a singly linked list that has more than two nodes, but I can't swap data? Also what would the Big-O complexity be for this?
A Queue is a linked list with pointers to both the head of the list as...
A Queue is a linked list with pointers to both the head of the list as well as the tail (or the last element) of the list. Given a queue Q, Q.head gives the head of the queue and Q.tail gives the tail of the queue. Give O(1) time algorithms for the following tasks. Enqueue • Input: A queue Q of distinct integers and a queue element a not in Q. 1 • Output: Q with the element a added...
In this code, I build a single-linked list using a node class that has been created....
In this code, I build a single-linked list using a node class that has been created. How could I change this code to take data of type T, rather than int. (PS: ignore the fact that IOHelper.getInt won't work for the type T... ie second half of main). Here's my code right now: public class SLList { public SLNode head = null; public SLNode tail = null; public void add(int a) {// add() method present for testing purposes SLNode newNode...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix it.. Can you explain to me what I am doing wrong? Warning: dlist.cc: In function 'std::ostream& operator<<(std::ostream&, dlist&)': dlist.cc:66:10: error: invalid initialization of reference of type 'std::ostream& {aka std::basic_ostream&}' from expression of type 'dlist::node*' dlist.cc: In function 'dlist operator+(dlist&, dlist&)': dlist.cc:93:8: error: invalid operands of types 'dlist::node*' and 'dlist::node*' to binary 'operator+' dlist.cc:97:8: error: could not convert 'result' from 'int' to 'dlist' My code:...
Helllp plz Allow the InsertAt method to add to the front position 0 (zero) also if...
Helllp plz Allow the InsertAt method to add to the front position 0 (zero) also if you try to add to a position greater than the number of nodes you get an error warning. /INSERT.C /*THIS PROGRAM READS A BINARY FILE (MUST ALREADY EXIST AND BE FILLED) */ /*AND PUTS IT INTO A LINKED LIST AND PRINTS THE LIST TO THE SCREEN) */ #include #include #include #include typedef struct ENTRY { char name[81]; }ENTRY; typedef struct LISTREC /* LISTREC is...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT