Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++! Having a really hard time comipling this. Here is the main that i have so far. Was able to get number 2 done but

C++! Having a really hard time comipling this. Here is the main that i have so far. Was able to get number 2 done but i need help getting the third. The image shows my main and my attempt. The code at the bottom is the Slinkedlist.h which i have tried to get to work. Any help is great. If you can get this to complie even better! this is for C++! thank you! Again not number 2 but number 3! number 2 is done! THANK YOU!

image text in transcribed

image text in transcribed

#ifndef Slinkedlist_h #define Slinkedlist_h

#include #pragma once #include using namespace std; template class SLinkedList; // forward declaration to be used when declaring SNode template class SNode { // singly linked list node private: E elem; // linked list element value SNode *next; // next item in the list friend class SLinkedList; // provide SLinkedList access }; template class SLinkedList { // a singly linked list public: SLinkedList(); // empty list constructor ~SLinkedList(); // destructor bool empty() const; // is list empty? E& front(); // return front element void addFront(const E& e); // add to front of list void addBack(const E& e); void removeFront(); // remove front item list int size() const; // list size void countVowel(const E& e); int numVowels() const; int numConsonants() const; //void reverse(const E& ptr); private: SNode* head; // head of the list int n; // number of items int vowelCount; int consonantCount; }; template SLinkedList::SLinkedList() // constructor : head(NULL), n(0), vowelCount(0), consonantCount(0) { }

template bool SLinkedList::empty() const // is list empty? { return head == NULL; // can also use return (n == 0); } template E& SLinkedList::front() // return front element { if (empty()) throw length_error("empty list"); return head->elem; } template SLinkedList::~SLinkedList() // destructor { while (!empty()) removeFront(); } template void SLinkedList::addFront(const E& e) { // add to front of list SNode* v = new SNode; // create new node v->elem = e; // store data v->next = head; // head now follows v head = v; // v is now the head n++; } template void SLinkedList::addBack(const E& e) { // create node SNode* v = new SNode; v->elem = e; v->next = NULL; countVowel(e); if(!head) { // empty list becomes the new node head = v; return; } else { // find last and link the new node SNode* last = head; while(last->next) last=last->next; last->next = v; } } template void SLinkedList::reverse(const E& ptr) { if (empty()) throw length_error("empty list"); SNode* old = head; // save current head while(old->next){ old->next = reverse(this); } head = old->next; delete old; } template void SLinkedList::removeFront() { // remove front item if (empty()) throw length_error("empty list"); SNode* old = head; // save current head head = old->next; // skip over old head delete old; // delete the old head n--; } template int SLinkedList::size() const { // list size return n; } template int SLinkedList::numVowels() const { return vowelCount; } template int SLinkedList::numConsonants() const { return consonantCount; } template void SLinkedList::countVowel(const E& e){ // list size if (isalpha(e)){ if(e == 'a' || e == 'A' || e == 'e' || e == 'E' || e == 'i' || e == 'I' || e == 'o' || e == 'O' || e == 'u' || e == 'U'){ vowelCount++; } // if (e == ' ') { // return; // } else{ consonantCount++; } } } #endif /* Slinkedlist_hpp */

#2 [6 points Use the template class SlinkedList discussed in class to implement a singly linked list of characters that store all the characters read from a line of text. The line of text will contain upper and lower case letters, digits, punctuation signs and white spaces. Add two member functions countVowel and countConsonant that count the number of vowels in the list, respectively the number of consonants in the list. For example, if the line of text given as a input is "Is dark at 6?!", the link list looks like: 6 The number of vowels is 3 and the number of consonants is 5. #3 [4 points] Given a singly linked list as in Problem 2, write a public member function void SLinkedList:reverseO to re-orient the next pointers of all the nodes in a list to each point to the previous element. Add a helper function as needed. Use the code available from SLinkedList.h on our Github https://github.com/apanangadan/CSUF-CPSC_131 with modification to illustrate your approach For the example given in Problem 2, the linked list will look like: 6

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions