C/C++ :: Print Single Linked List Backward With Functions / Classes - Error Message Regarding Header Files
Oct 11, 2014
I'm trying to print a single linked list backward with functions/classes. I have created the main file and 3 header files. But I'm getting an error on one of the header files, linkedListIterator after adding #include "linkedListType.h". It says that "linkedLlistType.h" is calling itself. And when I try to run it, I get an error of "too many header files." I have tried changing the headers many times, but nothing seems to work.
.cpp file:
/*(Printing a single linked list backward) Include the functions reversePrint and recursiveReversePrint, as discussed in this chapter, in the class linkedListType. Also, write a program function to print a (single) linked list backward. (Use either the class unorderedLinkedList or the class orderedLinkedList to test your function.)*/
I'm developing a stack using a linked list. I have to develop two friend functions to do something with the list. But I've tried to understand the friendship, without any consistent result.
Extract of code:
Code: class Element { public: int Data; Element *nextElement; Element(int Element) {Data = Element; nextElement = NULL;} ~Element() { }
[Code] ....
I have no errors, but I cannot access the private properties of the class.
The thing I would like to do is: sum the elements of the stack with a friend function.
I'm a beginner with C and wonder how to include single header files (*.h) in to my project. I mean header files which are not included to the standard installation package.
I thought it would work if I just copy the newheader.h file in to library folder c:MinGWinclude, but it didn't work. Is there some kinf of GCC -command or procedure to add these single header files or how it should work?
All of those standard header files are working well and I don't have any problems with them.
I currently have a running program "game.cpp" that runs a game of tic tack toe. I want to split the working functions into header files so that game.cpp isn't so cluttered. I have created two header files "displayBoard.h" and "gamePlay.h" but they wont compile because the functions are looking for variables that haven't been declared. First, here's the working code.
#include "displayBoard.h" #include <iostream> #include <limits> //This is required to catch invalid user input class ticTacToe //A class to contain all our functions {
what is the process to delete everything from a singly linked list. Like S= 1->2->3->... I want to remove all the values from S and reuse it again to store new datas.
I'm a little confused by my programming assignment this week. I've been working at it Wednesday and I've made progress but I'm still confused as to how I'm supposed to do this. The class I made is called Stack, and it's derived from a template class called StackADT. We also utilize a class called unorderedLinkedList, which is derived from a class called linkedList.
We're supposed to implement all of the virtual functions from stackADT in the Stack class. The Stack data is stored in a an unorderedLinkedList, so what I'm confused by is how to implement a few of the Stack functions because there are no functions in unorderedLinkedList which we could call to manipulate the data.
As you can see from my attached code, I'm really confused by how I'm supposed to implement the pop() and top() functions, and I also think my initializeList() function is wrong. We don't have any similar functions in unorderedLinkedList to call, so I'm at a loss of how i'd access my unorderedLinkedList. My initial thought was to call the similar functions in the class that unorderedLinkedList was derived from, linkedList, but I'm unsure of this is what we're supposed to do, or if theres actually a way to access my unorderedLinkedList without having to use the functions from the base class.
NOTE: We're not allowed to modify stackADT, unorderedLinkedList, and linkedList.
Stack.h
#include "stackADT.h" #include "unorderedLinkedList.h" template<class Type> class Stack: public stackADT<Type>{ template <class T> struct nodeType { T info; nodeType<T> *link;
how I would execute a nested class in a linked list... As example;
[Character][Weapon][Spell] classes are children of a [Base] class that stores normalized information such as 'Name'...
I am aiming to have a unique Character with a unique Weapon and Spell. I am trying to link-list these to have multiple characters. I just can't apply the design logic into programming logic.
cNode.h #pragma once #include "Includes.h" class cNode
I am trying to implement 2-D Linked Lists using classes. My program works fine for 1-D Linked List but I am having trouble understanding the syntax for using 2-D Linked Lists.
I was assigned to print a linked list but as a vector of char (I cannot use the normal string type) , this is what I have:
char* List::asString(){ Node* ite = new Node(); ite= first;//ite is like an iterator of the list for(int i=0; i<sizeOfList; ++i){//sizeOfList is the total of node of the list
[Code] ....
But when I print that, I get a bunch of weird symbols...
I have to write a c program that will allow the user to enter names with ages. The name will be no longer than 40 characters. The name and age should be stored in a node of a doubly linked list. I cant use global data. I need to use 3 subroutines. the first one needs to enter the data and pass the head and tail pointers to the subroutine. the next subroutine needs to print the names and ages to the screen and file output.txt from first to last. the last subroutine needs to print out names and ages to the screen and file output.txt from the last to first.
Im getting several errors when i try to run this program. The first subroutine to get the data from the user and build the double linked list. but i seem to be having issues.
#include <stdio.h> #include <stdio.h> #include <ctype.h> #include <string.h> int entry(char [][41], int []); // subroutine used for data entry // void printit(char [][41], int [], int); // subroutine used for data printing // void reverseprintit(char [][41], int [], int); // subroutine used for reverse data printing //
Implement a recursive function named void printBack(DoublyLinkedNode<T>* node) for the class DoublyLinkedCircularList which will print out the elements in the list from back to front. The function is initially called with the first node in the list. You may not make use of the previous(prev) links
This is my solution where I got 2 out of a possible 3 marks:
template<class T> void DoublyLinkedCircularList<T> :: printBack(DoublyLinkedNode<T>* node) { if(node->next == NULL) //Correct- 1 mark return 0; else printBack(node->next); //Correct - 1 mark cout << current-> element << " "; }
I have made a Template Class that I named ArrayList(to coincide with ArrayLists in Java)and it works for the primitive types string, int, double, etc.; however, when I try making the ArrayList with a class object instead of a primitive type it gives:
"error C2512: 'ArrayList<Missile>::listCell' : no appropriate default constructor available"
And I am not sure why. My ArrayList Class is defined by:
template <class type> class ArrayList{ struct listCell{ type dataStorage; listCell *next = nullptr;
[Code] ....
The error takes place in the add method of the ArrayList class:
void add(type toAdd){ size++; if (head == nullptr){ head = new listCell(); head->dataStorage = toAdd;
[Code] ....
only when I use a class object instead of a primitive storage type.
The class "Missile" has been defined and compiles successfully, and the code calling the add method is here:
ArrayList<Missile> missiles; Missile *missile; //Constructor and Deconstructor not shown void fire(){ missile = new Missile(xPos, yPos, true); missiles.add((*missile)); }
I dynamically allocate a new list in the recMergeSort function which should run a constructor but when it get to the functions that use it, I get error C2065: 'otherHead' : undeclared identifier. I have tried setting it to NULL and it didn't work. I even copied the default constructor to a set function and I still get the errors.
Code: template<class Type> void unorderedLinkedList<Type>::recMergeSort(nodeType<Type>* &head) { otherHead = new nodeType<Type>; if (head !=NULL) if (head->link != NULL)
[Code] ....
wonder if I'm sending the correct data type. Here is the heading of the functions that I'm using from the book.
I am trying to make a linked list. When I compile my code, I get an error saying 'current' is not declared in this scope. I don't understand because I have declared in the first line of my functions body. The variable is local to the function so I don't understand what the problem is.
#include <iostream> #include <cstdlib> using namespace std; class LinkedList { public: LinkedList() // default constructor makes an empty list
I created a simple program that writes some text to two different text files. how to create a program that would retrieve the information from those two files, and put them in a single file, first the content of input1 and then the content of input2. how to do this. Here is the program that I created that creates the two files.
#include <iostream> #include <fstream> #include <string> int main() { using namespace std; string input1; ofstream fout("input1.txt");
I've tried to form together the following code so that I can process multiple files from one user specified directory. However, when I run the program it works great for the first file, but all other files are blank. The problem starts on the following line: