Question

In: Computer Science

Could you please write a working program "linkedlist.cpp" using recursive approach for the given files below...

Could you please write a working program "linkedlist.cpp" using recursive approach for the given files below

--------------------------------------------------------------------------------------------

// app.cpp

#include <iostream>

#include "linkedlist.h"

using namespace std;

void find(LinkedList& list, char ch)

{

if (list.find(ch))

cout << "found ";

else

cout << "did not find ";

cout << ch << endl;

}

int main()

{

LinkedList list;

list.add('x');

list.add('y');

list.add('z');

cout << list;

find(list, 'y');

list.del('y');

cout << list;

find(list, 'y');

list.del('x');

cout << list;

find(list, 'y');

list.del('z');

cout << list;

find(list, 'y');

return 0;

}

--------------------------------------------------------------------

// linkedlist.h

#ifndef _LINKED_LIST_

#define _LINKED_LIST_

#include <ostream>

class LinkedList

{

public:

LinkedList();

~LinkedList();

void add(char ch);

bool find(char ch);

bool del(char ch);

friend std::ostream& operator<<(std::ostream& out, LinkedList& list);

};

#endif // _LINKED_LIST_

Solutions

Expert Solution

//app.cpp
#include<bits/stdc++.h>
#include "linkedlist.h"
using namespace std;

void find(LinkedList &list,char ch){
        if(list.find(ch))
                cout<<"found ";
        else
                cout<<"did not find ";
        cout<<ch<<endl;
}

int main(){
        LinkedList list;
        list.add('x');
        list.add('y');
        list.add('z');
        cout<<list;
        find(list,'y');
        list.del('x');
        cout<<list;
        find(list,'y');
        list.del('z');
        cout<<list;
        find(list,'y');
        return 0;
}

//linkedlist.h
#ifndef _LINKED_LIST_
#define _LINKED_LIST_
#include<iostream>
#include<ostream>
using namespace std;
class LinkedList{
        char v[1000];
        int count;
        public:
                LinkedList(){
                        count=0;
                }
                void add(char ch){
                        v[count]=ch;
                        count++;
                }
                bool find(char ch,int i=0){
                        if(i==count)
                                return false;
                        if(v[i]==ch)
                                return true;
                        return find(ch,i+1);    
                }
                bool del(char ch,int i=0){
                        if(i==count)
                                return false;
                        if(v[i]==ch){
                                for(int j=i+1;j<count;j++)
                                        v[j-1]=v[j];
                                count=count-1;
                                return true;
                        }
                        return del(ch,i+1);
                }
                ~LinkedList(){
                        count=0;
                }
                friend ostream& operator << (ostream& out,const LinkedList& list);
};
ostream& operator << (ostream& out,const LinkedList& list){
        for(int i=0;i<list.count;i++){
                out<<list.v[i]<<" ";
        }
        out<<endl;
        return out;
}
#endif

The code is working and the output is attached below:


Related Solutions

Could you please write "linkedlist.cpp" using recursive approach to manage a linked list for the given...
Could you please write "linkedlist.cpp" using recursive approach to manage a linked list for the given files below as well as an updated makefile. // app.cpp #include <iostream> #include "linkedlist.h" using namespace std; void find(LinkedList& list, char ch) { if (list.find(ch)) cout << "found "; else cout << "did not find "; cout << ch << endl; } int main() { LinkedList list; list.add('x'); list.add('y'); list.add('z'); cout << list; find(list, 'y'); list.del('y'); cout << list; find(list, 'y'); list.del('x'); cout <<...
write code to manage a linked list using recursive approach. (Using this code) C++ IN Unix....
write code to manage a linked list using recursive approach. (Using this code) C++ IN Unix. // app.cpp #include <iostream> #include "linkedlist.h" using namespace std; void find(LinkedList& list, char ch) {    if (list.find(ch))        cout << "found ";    else        cout << "did not find ";    cout << ch << endl; } int main() {    LinkedList   list;    list.add('x');    list.add('y');    list.add('z');    cout << list;    find(list, 'y');    list.del('y');    cout...
Please if you are able to answer the question below: Write C++ program using native C++...
Please if you are able to answer the question below: Write C++ program using native C++ (you can use STL)  that produces Huffman code for a string of text entered by the user.  Must accept all ASCII characters.  Pleas explain how you got frequencies of characters, how you sorted them, how you got codes.
Problem 1: Recursive anagram finder please used Java please Write a program that will take a...
Problem 1: Recursive anagram finder please used Java please Write a program that will take a word and print out every combination of letters in that word. For example, "sam" would print out sam, sma, asm, ams, mas, msa (the ordering doesn't matter) input: cram output: cram crma carm camr cmra cmar rcam rcma racm ramc rmca rmac acrm acmr arcm armc amcr amrc mcra mcar mrca mrac macr marc Hints: Your recursive function should have no return value and...
JAVA There is a folder named Recursive folder at the same location as these below files,...
JAVA There is a folder named Recursive folder at the same location as these below files, which contains files and folders. I have read the data of the Recursive folder and stored in a variable. Now they are required to be encrypted and decrypted. You may copy past the files to three different files and see the output. I am confused on how to write code for encrypt() and decrypt() The names of files and folders are stored in one...
Could you please improve my program with the method below? Improve the appointment book program of...
Could you please improve my program with the method below? Improve the appointment book program of PA5 Exercises P9.3 and P9.4 by letting the user save the appointment data to a file and reload the data from a file. The saving part is straightforward: Make a method save. Save the type, description, and date to a file. public static void save(String file, Appointment appointment) throws IOException {...} For the loading part, first determine the type of the appointment to be...
In C++ Please, using only the libraries given in this homework prompt, Write a program that...
In C++ Please, using only the libraries given in this homework prompt, Write a program that (1) prompts for two integers, (2) prints out their sum, (3) prints out the first divided by the second, and (4) prints out the natural log of the first number raised to the power of the second number. #include <iostream> #include <iomanip> using namespace std; int main() { <your answer goes here> return 0; }
Parse string java code Write a recursive program that can calculate the value of a given...
Parse string java code Write a recursive program that can calculate the value of a given polynomial in a string, which is not more than the tenth order, for the given x. The polynomial will be given in the following format and should display the value of the polynomial for spaced-out x Using index of for -/+
a) Based on the binary tree implementation from the Python program below  write a recursive method that...
a) Based on the binary tree implementation from the Python program below  write a recursive method that calculates the number of leaf nodes in the tree. class Binaertre: def __init__(self, datatobjekt): self.data = datatobjekt self.forelder = None self.venstre_barn = None self.hoyre_barn = None @property def venstre_barn(self): return self.__venstre_barn @venstre_barn.setter def venstre_barn(self, node): self.__venstre_barn = node if node is not None: node.forelder = self @property def hoyre_barn(self): return self.__hoyre_barn @hoyre_barn.setter def hoyre_barn(self, node): self.__hoyre_barn = node if node is not None: node.forelder...
C++ Goals: Write a program that works with binary files. Write a program that writes and...
C++ Goals: Write a program that works with binary files. Write a program that writes and reads arrays to and from binary files. Gain further experience with functions. Array/File Functions Write a function named arrayToFile. The function should accept three arguments: the name of file, a pointer to an int array, and the size of the array. The function should open the specified file in binary made, write the contents into the array, and then close the file. write another...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT