I need help with this C++ program. Code with comments would be great. Here is wh
ID: 3772125 • Letter: I
Question
I need help with this C++ program. Code with comments would be great.
Here is what I have so far which isnt much but it is something:
#include <iostream>
#include <string>
using namespace std;
struct sortedListNode
{
char letters;
int occurrances;
sortedListNode*next;
};
sortedListNode*head = NULL; // empty list
sortedListNode*temp = (sortedListNode*)malloc(sizeof(sortedListNode));
void fromString(sortedListNode*data)
{
string data;
}
void main()
{
string word1;
string word2;
sortedListNode list1;
sortedListNode list2;
sortedListNode list3;
cout << "Enter first word: ";
cin >> word1;
cout << "Enter second word: ";
cin >> word2;
}
Once again help with comments would be great because I can not wrap my head around the concept of linked lists and pointers.
User will input 2 words; the characters in each word will be loaded into a sorted linked list. Use a struct containing data of char variable "letter" and int variable "occurrences" plus the pointer to the next element of the list. Letters can be used more than once in the list with the occurrences field updated. Once the lists are created use the overloaded operator+ to combine the the word but appear only once in lists together into one list. Use the following main to test your code: sortedListNode listl; sortedListNode list2 sortedListNode list3; cout > wordl; cout word2; list! fromstring (word! ); //word one to list coutExplanation / Answer
#include <iostream> //include header file for input output
#include <string> // include string handling header file
using namespace std;
struct sortedListNode //define structor for sortedlistnode
{
char letters;
int occurrances;
sortedListNode*next;
};
sortedListNode*head = NULL; // empty list pointer
sortedListNode*temp = (sortedListNode*)malloc(sizeof(sortedListNode)); // assign memory of sortedListNode and pointed by temp
void fromString(sortedListNode*data) //functon defination of function fromString with argument as pointer of sortedListNode
{
string data; //local declaration of string variable data
}
void main()
{
string word1; // declare string variable word1
string word2; //declare string variable word2
sortedListNode list1; //declare sortedListNode variable list1
sortedListNode list2; //declare sortedListNode variable list2
sortedListNode list3; //declare sortedListNode variable list3
cout << "Enter first word: "; //print
cin >> word1; //take input from user and put in word1
cout << "Enter second word: "; //print
cin >> word2; //take input from user and put in word2
}