C++ :: Overload Operator With Stack That Implements Linked List

Nov 10, 2013

struct Node {
int entry;
Node *next;
Node(); //1
Node(int item, Node *link = NULL); //2

[Code] .....

Implement: 1 2 3 4 5
and overload operator <<, >>, =

View 1 Replies


ADVERTISEMENT

C++ :: Mid Of Stack Using Linked List

Apr 1, 2013

I am unable to make any logical algorithm to access middle of stack. I am using stack implemented with linkedlists, I have following functions available for stack like push,pop,top.

View 6 Replies View Related

C++ :: Namespaces / Classes - Perform Operator Overload With Insertion Operator

Mar 22, 2013

I'm doing a refresher for C++ and have gotten to operator overloading. I'm trying to perform an operator overload with the insertion (<<) operator, but I have encountered a problem.

Here's my class [In a header file "Shinigami.h"]

#include<string>
namespace K{
class Quincy;
class Shinigami{
friend std::ostream& operator<<(std::ostream&, const Shinigami&);

[Code] .....

If the operator function is a friend of the 'Shinigami' class, why doesn't it recognize any of it's private members? I need it to be in this file because I'm doing a bit of association with the 'Quincy' class.

I thought it was the namespace, but I included that.

View 9 Replies View Related

C++ :: Stack Based Linked List

Oct 23, 2014

I am trying to program a stack based linked list. Something very weird is happening with my program. Whenever i want to print with cout<< in specific places, it actually changes the data of the stack. Also, using endl after the cout also changes the data of the program.

#include <iostream>
using namespace std;
class node {
public:
int number;
node* nextPtr=NULL;

[Code] ....

View 7 Replies View Related

C/C++ :: Implementing Stack Using A Double Linked List

May 12, 2014

So im trying to write a code that will take data in from a user and when that user enters specific character then i want to pop the top of the stack and place that node on a new stack. Then if the user enters a different specific character then i want to place what was just popped off the stack back on to the original stack. Anyways i'm just testing what i have without all the complicated stuff with the specific characters, but i get an error and i'm not not well versed in exception handling. So this is what i have so far. the push seems to work well but the pop seems to be giving me problems.

Stack::Stack(){
top = NULL;
bottom = NULL;
}
//method to push a line of text onto the stack
void Stack::push(string data)

[Code] .....

View 4 Replies View Related

C++ :: Array Versus Linked List Implementation For Stack

Nov 27, 2014

Basically what are the advantages and disadvantages of having an array implementation vs linked list implementation for a stack?

View 1 Replies View Related

C/C++ :: Linked List Implementation Of Stack For ReverseRows In Matrix

Nov 29, 2014

I had the following question in my exam paper and only got 2.5 out of a possible 7 marks.

Given the Matrix class:

class Matrix {
public:
Matrix(unsigned r, unsigned c);
Matrix(const Matrix<T>& rhs);
~Matrix();
const Matrix<T>&operator=(const Matrix<T>& rhs);

[code]....

Use the linkedStackType class (Linked list implementation of stack) and write a function reverseRows to reverse the order of rows in the matrix. Note that reverseRows is not a member function of the Matrix class therefore only the public interface of matrix can be used.

template<class Type>
struct nodeType {
Type info;
nodeType<Type> *link;

[code]....

View 2 Replies View Related

C++ :: 2D Array To Simulate Linked List For Stack Construction

Feb 13, 2013

I'm trying to implement 2d array to simulate linked list for stack and I faced several difficulties doing so.

How do I implement from Top to Bottom ordering? How do I check random index value for validity?

Source-code:

Code:
#include <iostream>
using namespace std;
int myTop, index, nex = -1;
int twoDimentionalArray[25][3], L[25];

[Code].....

And one more thing: how do I get straight 0 from 25 index in the first coulumn?

View 1 Replies View Related

C++ :: How To Overload Operator Twice

Jul 10, 2014

Here's my question. I'm coding a basic Linked List class (for the purpose of understanding and having fun, I know about STL), LList.

I have overloaded the [] operator so it returns the data of the index-th node in the list, for example, if I code

LList x;
....
cout<<x[5];

it prints the data of the 5th node in the list (for fun I decided to index from 1 to infinity).

My question: Now I want to be able to assign the value to the index-th node data, using [] and =, for example, I want to be able to write:

LList x;
.....
x[5] = 121;

How can I do that?

View 3 Replies View Related

C++ :: How To Able To Overload A Multiplication Operator

Apr 24, 2014

How would i be able to overload a multiplication operator that if, in the main example(0, 5, 0) * example (0, 5, 0) is given, it gives me 25?

View 1 Replies View Related

C/C++ :: How To Access Linked List Functions From Stack Class Without Functions

Mar 20, 2014

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;

[Code]...

View 3 Replies View Related

C++ :: Dealing With Operator Overload Function Failure

Aug 23, 2014

Say I have a class that requires dynamic allocation to implement a few of the operators. Take "+" for example; I need to create a new object to hold the sum of the two parameters whose size is not known at compile time.

I'm pretty sure the standard way to indicate a failure inside the overloading function would be to throw an exception. However I am currently involved in an embedded(ish) project where the spec. says no exceptions are to be used.

I think I have 2 options:

1. Return an "invalid" object (with a flag indicating an error has occurred) and check for this after each operation.

a = b + c
if (a.err)
// handle error
or

2. To forsake operator overloading entirely and think up a new way of doing things where all functions that involve dynamic allocation can return error codes. but this seems rather terrible too as I may end up with something like:

objA a
if (add(&a, b, c) == -1) // assuming b and c are initialized before this snippet starts
// handle error

Is there a number 3 that I haven't thought of? It seems that not allowing exceptions is fairly common even in the non-embedded world [URL] so how is this normally done? or is operator overloading usually avoided when exceptions are not allowed?

View 3 Replies View Related

C++ :: Overload Delete Operator With Specific Arguments

Sep 27, 2014

We're trying to overload the delete[] operator with specific arguments. Which is the right way to call it? We use the GNU compiler and obtain compiler errors with all of these samples:

#include<iostream>
using namespace std;
typedef unsigned int P;

[Code]....

View 2 Replies View Related

C++ :: Union Of Two Vector ADT Bags - Operator Overload

Apr 30, 2014

I'm trying to come up with the union of two Vector ADT bags, so I have to overload the '+' operator, but I'm getting a bunch of error messages saying:

VectorBag.cpp: In instantiation of ‘VectorBag<ItemType> VectorBag<ItemType>::operator+(VectorBag<ItemType>) [with ItemType = int]’:
proj2.cpp:161:42: required from here
VectorBag.cpp:81:24: error: no match for ‘operator[]’ (operand types are ‘VectorBag<int>’ and ‘int’)
newBag.add(anotherBag[i]);
^
Here is the function to overload the operator:

template<class ItemType>
VectorBag<ItemType>
VectorBag<ItemType>::operator+(VectorBag<ItemType> anotherBag) {
VectorBag<ItemType> newBag;
for (int i = 0; i < anotherBag.getCurrentSize(); i++)
newBag.add(anotherBag[i]);
}

The add() function is pre-defined by me somewhere else in the code. It basically does push_back().

View 4 Replies View Related

C/C++ :: Overload Operator With Friend Function Using Constructors

Dec 26, 2014

I want to overload prefix and postfix increment(++) operators with friend function. I also have to use the constructors for this. How can I do this? in C++

View 4 Replies View Related

C++ :: Call Text File In Input Overload Operator?

Nov 12, 2013

i am doing some practice problems and i can't seem to figure out how to do this. basically we have a students number of test scores, then the name followed by the scores they have in a text file. Then we have to make a class with a constructor, copy constructor, destructor, and overload the = operator and the input and output operator. Are we suppose to call the text file in the input overload operator?

Here is what i have so far.

This is my header file.

#ifndef STUDENTTESTSCORES_H
#define STUDENTTESTSCORES_H
#include <string>
#include <iostream>
using namespace std;
class StudentTestScores{
private:
string studentName;

[Code]...

i am 100% sure the overloading the input is wrong

here is the implementation of the constructor copy constructor and desctructor

#include <iostream>
#include "StudentTestScores.h"
using namespace std;
StudentTestScores::StudentTestScores(string name = "", int numScores = 0)
{
studentName = name;
numTestScores = numScores;
if (numScores <= 0)
testScores = NULL;
else

[Code]...

and here is the notepad file

3
Justin Bieber491.469.184.681.081.5
Miley Cyrus380.080.090.083.3
Kim K490.575.661.481.677.2

The program is suppose to use all the information and read from the notepad and output the exact things as the notepad file

View 7 Replies View Related

C++ :: Error When Using Volatile Object In Overload Assignment Operator

Jul 27, 2012

/*using GENERIC_COMMAND* A; as volatile generates error. but here i have to use union object as volatile i.e. volatile GENERIC_COMMAND* A; */

#include <iostream>
using namespace std;

typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
union GENERIC_COMMAND {

[Code] .....

View 14 Replies View Related

C++ :: Write Prototype Of A Member Function To Overload Insertion Operator

Apr 10, 2014

Consider the class specification below. Write the prototype (i.e. header) of a member function to overload the insertion operator (i.e. <<). The << operator is to output the data members of an instance of class StudentTestScores into an output stream. Your definition should allow for chaining of output operations (e.g. cout << x << y; where x and y are of type StduentTestScires).

#include <string>
using namespace std;
class StudentTestScores{
private:
string studentName;
float *testScores; // used to point to an array of test scores
int numTestScores; // number of test scores

[code]....

View 1 Replies View Related

Visual C++ :: Operator Overload Not Defined Error When Type Accessed Through Const Struct

Oct 17, 2012

I have a basic vector/point class where I've overloaded a bunch of arithmetical operators:

Code:
#pragma once
class point {
public:
point() {
}
point(float p_x, float p_y, float p_z) : x(p_x), y(p_y), z(p_z)

[Code] ...

I can use it fine like

Code:
point p(50,50,50);
point q(50,50,50);
point t = p * q + q;

However when I put this point type into a struct and try to access the members after passing it through by const reference:

Code:
struct sextic {
point a,b,c,d,e,f,g;
};
inline static sextic sexticDifference(const sextic &p_sextic1, c

[Code] ....

This gives me an "operator not defined" error for compilation.

View 2 Replies View Related

Visual C++ :: Circular Buffer - No Instance Of Overload Function Matches Argument List

Nov 25, 2014

I'm having some issues with my code. For the produce function i am getting an error saying 'no instance of overload function produce() matches the argument list' and also for the lines buffer[head].data = message; buffer[head].time = current_time i get an error saying 'expression must have pointer to object type.

In the code i'm not sure if i passed the variables to the function correctly. I have attached the code .....

code produce.txt

View 14 Replies View Related

C++ :: Stack Implementation Of Linked Lists

Jun 7, 2014

I have this code that I need to memorize for my final. Memorizing code is easy for me, but I'm trying pretty hard to fundamentally understand the functions, and what they are doing (even using pen and paper, to draw and trace).For example, in the push function below, I understand everything, except why I'm setting ptr = p. I feel like p should be equal to NULL, then the next node I push should be equal to p, etc.

Stack & Stack::push(double x)
{
Node * p = NULL;
try
{
p = new Node;
}

[code].....

Also, are LL Queues that hard to implement once you can do them w/stacks - That will probably be something I have to code for my final, as well. Below is the full code for my Stack class.

#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
class Stack
}

[code]....

View 1 Replies View Related

C# :: How To Stack List Items

Nov 18, 2014

I do some research about getting the coordinates from the list items but without success. I would like to make that when i press down my mouse button that little blocks fall "out" my mouse and stack on top of eachother.

that first works. When i press the mouse button i draw squares and the fall to the bottom of the screen, but the stack part not.

here is my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;

[Code]....

View 14 Replies View Related

C++ :: Creating A Linked List Of Common Elements From Two Other Linked Lists

Apr 29, 2013

I'm trying to write a function that takes two linked lists and creates a third one with only the common elements.

It assumes the first list (the caller) has no dups, but it doesn't seem to be working. The program doesn't crash, it just hangs when it is supposed to display L3 (the third list)..everything else runs and is displayed fine.

template <typename T>
LList <T> LList <T>:: common (LList <T> &B)//common fct
{
Node <T> *hunter1 = Head;

[Code]......

View 10 Replies View Related

C++ :: Class DayType That Implements Day Of Week In A Program

Aug 15, 2013

Write the definition of the class dayType that implements the day of the week in a program. The class dayType should store the day, such as Sunday for Sunday. The program should be able to perform the following operations on an object of type dayType:

a. Set the day
b. Print the day
c. Return the day
d. Return the next day
e. Return the previous day
f. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add 4 days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.
g. Add the appropriate constructors

Write the definitions of the functions to implement the operations for the class dayType.

My code:

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string my_Day[7] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
class dayType

[Code] .....

And here are the error messages that I get:

Line 23 error: prototype for 'void dayType::setDay(int)' does not match any in class 'dayType'
Line 11 error: candidate is: void dayType::setDay()
Line 36 error: prototype for 'void dayType::getDay(int) const' does not match any in class 'dayType'
Line 13 error: candidate is: void dayType::getDay()

I know this is probably a really easy mistake but I am new to Programming and I have changed this code for days to no avail.

View 2 Replies View Related

C :: Insert Linked List Into Another Linked List

Jun 29, 2013

I have a linked list comprised of chars like so...

Code:

node1 - "p"
node2 - "o"
node3 - "p"

I need a function that will take in three perameters...node *replaceChar(node *head, char key, char *str)Stipulations of this function. head is the head of the list, 'key' and 'str' are guaranteed to contain alphanumeric characters only (A-Z, a-z, and 0-9). str can range from 1 to 1023 characters (inclusively). So if I call this function with these perameters..

Code:

node *head == /*the head of the list to be examined*/
char key == "p"char *str == "dog"The new list will look like this...
node1 - 'd'
node2 - 'o'
node3 - 'g'
node4 - 'o'
node5 - 'd'
node6 - 'o'
node7 - 'g'

All instances of 'p' were replaced with 'dog' I have a toString function which takes in a string and converts it to a linked list and returns the head. So assume that you can call the function on str = "dog" so...

Code:

toString(str) == /*this will return the head to the list made from the str*/

If it's unclear what my question is...I am stumped on how to write the replaceChar function the one that takes in three perameters..

View 3 Replies View Related

C++ :: Overloading Plus Operator For Linked Lists (binary Numbers)

Mar 1, 2013

I have tried to understand the concept of linked lists and I have read the assigned chapter 2 times. My teacher is a little laid back when it comes to teaching! This is only a portion of my program. This function is supposed to add 2 binary numbers 11101+1101 and store the result in the temp list. The answer I get is 10000.I don't think that it is adding the carry.

binary operator+( binary num1, binary num2) {
binary temp;
int carry, sum;

[Code]..

View 19 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved