C++ :: Removing Element From Template Linked List?

Nov 11, 2013

I have been trying to implement a way to remove a post from a list of posts implemented with a template doubly linked list. I have thought that the best way to do this might by operator overloading, but I have digressed. I have just thought of using a isEqual that checks equality, but when trying to implement i'm getting weird errors.

This is within my class wall, which is a linked list of wall posts, getPostInfo is within the class WallPost.

bool isEqual(WallPost const & a, WallPost const & b)
{
if(a.getPostInfo() == b.getPostInfo())
return true;
else
return false;
}

I have several instances of the error "void illegal with all types" on line 3. It also is complaining about a not being a arithmetic, unscoped enum, or pointer type. I am assuming that it is because my getPostInfo function is a void.

View 16 Replies


ADVERTISEMENT

C++ :: Linked List - Function Which Deletes Element If Next Element Is Bigger

Mar 10, 2014

So I have linked list and function which deletes element if next element is bigger, so my code is working but its not working with first element, in the comment I have wrote code which I would code for checking that first element, but when ever I check it is blowing up all program.

#include <iostream>
using namespace std;
struct llist {
int x;
llist *next;

[Code] .....

View 1 Replies View Related

C :: Removing A String - Linked List

Feb 19, 2013

I'm trying to go search through my linked list for a passed string and if it matches, remove it...but obviously link everything back together properly. This is what I have so far but when i pass it to my display function, which is properly working, it goes into an endless loop

Code:
void llRemoveString(LinkedList** ll, char* string) {
LinkedList* newNode = (LinkedList*)malloc(sizeof(LinkedList));
newNode->value = string;
LinkedList* n = *ll;

[Code] ....

View 8 Replies View Related

C++ :: Removing First Item From Single Linked List

Oct 10, 2013

My algorithm is not working

void remove_first() {
current_node = head_node;
node * temp_node = current_node;
current_node = current_node->get_next();
head_node->set_next(current_node);
delete temp_node;
temp_node = NULL;
}

View 2 Replies View Related

C :: Linked List / Adding Element To Beginning Of List

Dec 31, 2014

Code:

// Write a function called insertEntry() to insert a new entry into a linked list.

Have the procedure take as arguments a pointer to the list entry to be inserted (of type struct entry as defined in this chapter), and a pointer to an element in the list after which the new entry is to be inserted.

// The function dveloped in exercise 2 only inserts an element after an existing element in the list, thereby prenting you from inserting a new entry at the front of the list.

(Hint: Think about setting up a special structure to point to the beginning of the list.)

#include <stdio.h
struct entry1 {
int value;
struct entry1 *next;
};

[code]...

This is a working version of the exercise, but I don't think I'm doing what's asked. I was able to add an element to the beginning of the list using an if statement, not creating a special structure that points to the beginning of the list. How would I go about creating a special structure that points to the beginning of the list to add a new element at the beginning of the list?

View 8 Replies View Related

C++ :: Remove Element From Linked List?

Jun 6, 2013

This code is from a example in Jumping Into C++ and I understand the example. But it is a practice problem that is to write a program to remove an element from a linked list; the remove function should take just the element to be removed.

Code: #include <iostream>
using namespace std;
struct EnemySpaceShip {
int x_coordinate;
int y_coordinate;

[Code]...

If I got this right I will create a pointer that points to the first SHIP (getNewEnemy) and the other one will not be printed out.

View 7 Replies View Related

C++ :: Remove Element In Linked List

Oct 17, 2014

This is my current code. The code is to remove the element in the list "head" that is "e". The code works if there is only one element in the list but if there are more than 1 element in the list, it doesn't work. The function should return true if there is an element that equals "e" and then it removes it and false if no element equals "e".

bool StringLinkedList::remove(const std::string& e){
StringNode* current = head;
int i = 0;
if (current == NULL)
return false;

[Code] ....

View 1 Replies View Related

C++ :: Search For Element By Name - Printing Linked List

May 2, 2014

I've got this program that I'm working on. Most of the code is from a video tutorial, but I was editing it to be able to search for an element by name. That's working fine, but suddenly the part of the program that prints out all the elements starts in an infinite loop after I input two elements, and search for one.

Here's what I've got:

[code#include <iostream> usingnamespacestd; struct node { int number; string name; node *next; }; bool isEmpty (node *head); char menu (); void insertAsFirstElement (node *&head, node *&last, int number); void insertSorted(node *&head, node *&last, int number); void remove(node *&head, node *&last); void showList (node *current); void showByName (node *current, string name); bool isEmpty (node *head) { if (head == NULL) { return true; } else { returnfalse; } } char menu () { char choice;

[Code] .....

View 8 Replies View Related

C++ ::  Sum Up Price Element In Node Of Linked List?

Sep 6, 2014

I'm trying to calculate the total price of books contained in a linked list. I've tried getTotal() function in linked list but error: no match for 'operator+=' in 'total += ptr->Node<Book>::info'| occurred. How can I access the price in the node and then calculate the total price.

Here is part of my code :

Book class
class Book {
protected :
int id;
string title;
double price;
string bookStatus;

[code]....

View 2 Replies View Related

C :: Function To Return First Element Of Linked List Queue

Feb 23, 2013

I am trying to write a function to return the first element of a link list queue. I am not real sure how to implement this. I have include a copy of the struct for my Node & queue.

Code:

typedef struct event_Node {
void *data;
double arri_time;
double serv_time;
double depart_time;
double start_o_serv;

[Code]...

View 4 Replies View Related

C++ ::  Modify Element In Node Of Linked List With Value Assignment

Sep 7, 2014

I tried to modify staff name with an assignment value of other string but couldn't work it out. I managed to modify it by key in cin >>.

The purpose is that I want to assign string value from other different class to Staff class. An error : no match for 'operator=' in '* updateName = newStaffName' and note: no known conversion for argument 1 from 'std::string {aka std::basic_string<char>}' to 'const Staff&' occurred.

#include <iostream>
using namespace std;
class Staff {
friend ostream& operator << (ostream& os, Staff& m) {
os << "[" << m.ID << ", " << m.fName << "]";

[Code]...

View 3 Replies View Related

C++ :: Removing Element From Map?

Jun 20, 2013

I have a map as below. MoTopImpl is a class.

Map<MoTopImpl*,os_Reference_protected<MoTopImpl> > map_;

The map is populated as below:

void setMoInMap(MoTopImpl* mo,MoTopImpl* me) {
map_[mo] = me;
}

Now, I want to remove a specific element from this map. I am passing the element to be removed to the remove function as below:

void Asap::removeMoFromMap(MoTopImpl* mo) {
// First solution
if (mo != 0) {

[Code]....

And the function removeMoFromMap is called as below:

MoTopImpl* moTop = getMoTopImpl();
if (moTop != 0)
removeMoFromListMosSuspended(moTop);

But I am able to empty the map by iterating through the complete map as below:

Mapiter<MoTopImpl*,os_Reference_protected<MoTopImpl> > moIter(map_);
for (moIter = map_.first(); moIter; moIter.next()) {
moIter.remove();
}
cout << "Map zise = " << map_.size() << endl; // Prints zero

View 6 Replies View Related

C/C++ :: Linked List Template Search

Feb 6, 2015

I have a linklist program I've written that seems to work just fine at least, it outputs the right information. However when it comes to the end and says press any key to continue, it crashes when I press a key says debug assertion error rather than just exiting. I haven't gone back and put in comments yet, I know I need to get used to commenting as I go />/>

#ifndef LIST_H
#define LIST_H
#include <iostream>
#include <cstdlib>
using namespace std;
template <class T>
class LinkList {

[Code] ....

Another bit of information. It was working without crashing when I only had the intlist functions called. When I added the doublelist is when I began getting the error however now if I remove the doubelist and go back to just having the intlist calls it still gives the error.

View 9 Replies View Related

C/C++ :: Error C2512 With Template Linked List?

Oct 29, 2013

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));
    }  

why this causes an error?

View 3 Replies View Related

C :: Last Element Of List Overwritten By First Element Of Another

Feb 23, 2013

I have a global list that contains smaller lists of char arrays. I have an issue where when I'm reading back the inner lists the last element of one list seems to point to first element of the next.

So my data looks like the below (values separated by commas with the pairs separated by tabs. The last pair in a line is the same as the first). When I read the first list back instead of seeing "456.678,678.98" as the last element in the list. I see "435.67,234.98" twice: at the end of the first list and start of the other. I have debugged when the list is populated and can see the correct values going in so I can't figure what's happening.

456.678,678.98 123.45,345.56 256.67,789.98 456.678,678.98
435.67,234.98 123.65,342.56 987.78,678.34 435.67,234.98

Code to fill the list:

obstacle_list = op_prg_list_create();
while (fgets(line, sizeof(line), obstaclePositions_traj_file) ) {
token = strtok(line, "
"); //Pull the string apart into tokens using the

input = op_prg_list_create();

[Code] ....

View 3 Replies View Related

C++ :: Std List - How To Get Value Of Element 2 Minus Element 1

Aug 23, 2012

I have an std list of type double.. and the list is always guaranteed to have just 2 elements. I need to get the value of element 2 minus element 1. What is the least amount of code to accomplish that?

I tried this:

Code:
list<double> dList;
dList.push_back(1.0);
dList.push_back(2.0);
list<double>::iterator iter = dList.begin();
list<double>::iterator iter2 = dList.end();
double result = *iter2 - *iter;

But this code does not work. Why not?

View 6 Replies View Related

C++ :: Use Of Class Template Requires Template Argument List

Nov 6, 2013

Error1error C2955: 'DoubleLinkedListInterface' : use of class template requires template argument listdoublelinkedlist.h10
Error2error C2244: 'DoubleLinkedList<T>::DoubleLinkedList' : unable to match function definition to an existing declaration doublelinkedlist.cpp7

Error3 .cpperror C2244: 'DoubleLinkedList<T>::~DoubleLinkedList' : unable to match function definition to an existing declaration 12

.h

#pragma once
#include "DoubleLinkedListInterface.h"
#include "Node.h"
#include <iostream>

[Code]....

View 4 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++ :: How To Remove Element In A List

Mar 27, 2013

How can I remove an element in a list when I have only an iterator that points to the object I want to remove. Is there a build in command? remove() takes an object reference as its argument. Is it possible to convert the iterator into a pointer type so it can be deferenced and passed to remove?

This is the code I am working on:

//player.cpp
void Player::CheckCollectableCollisions(std::list<Collectable>& c) {
std::list<Collectable>::iterator i = c.begin();
while(i != c.end()) {
if (Collider::CheckCollision(pNodes_.front().getLocation(), i->getLocation()))

[Code] .....

View 2 Replies View Related

C# :: How To Get A Specific List Element

Nov 26, 2014

Here's my list code:

Color.FromArgb(alfa, 0, 255, 255),
Color.FromArgb(alfa, 0, 255, 0),
Color.FromArgb(alfa, 64, 255, 0),
Color.FromArgb(alfa, 128, 255, 0),
Color.FromArgb(alfa, 192, 255, 0),
Color.FromArgb(alfa, 255, 255, 0),
Color.FromArgb(alfa, 255, 192, 0),
Color.FromArgb(alfa, 255, 128, 0),
Color.FromArgb(alfa, 255, 64, 0),
Color.FromArgb(alfa, 255, 0, 0)

How can I get a specific element value from that list?

For example:

if(true)
{
//get "192" from Color.FromArgb(alfa, 255, 192, 0)
}

I don't see the "Edit" option and I've noticed a slight error in the previous post.There should be, obviously, [code]if(true)

{
//get "192" from Color.FromArgb(alfa, 255, 192, 0)
}

I was missing the closing tag.

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 :: Delete Each Element In The List Which Is Same - Function Does Not Work Properly

Jan 18, 2014

Code:

struct lista* del(struct lista* p, char* path1) {
char model[MAX2];
int len;
char ch;
printf("Type model.

[Code] ..... t

This function should delete each element in the list which is the same as this one typed by user. There are no errors, but function doesn't work. It deletes something, but not this element which should.

View 5 Replies View Related

C/C++ :: Remove All Instances Of Element Within List - While Loop Error

Jun 23, 2014

I am getting an error with my while loop(feels dumb) when running this code that I am allowed to modify. It is to remove all instances of an element within the list.

The loop is whithin this function:

void arrayListType<elemType>::removeAll(int location)

I have attached both the header file and main function file in .txt format.

void arrayListType<elemType>::removeAll(int location)*

Attached File(s) : 
header.txt (12.23K)
main function.txt (2.95K)

View 2 Replies View Related

C++ :: Linked List Delete List?

May 30, 2013

I'm working on a linked list and was wondering how this looks to everybody else for a deleteList function.

void deleteList(Node* head)
{
Node* iterator = head;
while (iterator != 0)

[code].....

View 6 Replies View Related

C++ :: Invalid Use Of Template Name ND Without Argument List

Dec 31, 2013

#ifndef BSTCLASS_H_
#define BSTCLASS_H_
#include <string>
using namespace std;

[Code]....

-'ND' is not a type; when I use it as a parameter
or
-invalid use of template name 'ND' without argument list; when I use it as a return type.

On some lines I try access the elements inside of 'ND' variables and I get errors saying that those elements don't exist for the given pointers.

View 4 Replies View Related

C++ :: Trying To Add Template Class To Maintain List

May 12, 2013

I wrote this menu-driven program that maintains a list of restaurants. The program runs fine as it is right now, but my problem is I need to create a new array template class to maintain the list of restaurants, and when a new restaurant is added it must be created dynamically.

I'm having a hard time figuring out what exactly I need to do for this. Templates confuse me allot and I've read all the sections on templates here and in my book, but i'm still lost. The dynamic memory part is throwing me off as well.

main.pp

#include <iostream>
#include <string>
#include <iomanip>
#include "Restaurant.h"

[Code]....

Restaurant.h

#pragma once
#include <iostream>
#include <string>
#include "FTime.h"
using namespace std;

[Code]....

Restaurant.cpp

#include "Restaurant.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
using namespace std;

[Code]...

FTime.h

#pragram once
#include <string>
using namespace std;
//class FTime
class FTime {
friend ostream& operator<<(ostream& out, const FTime& obj);

[Code]...

View 3 Replies View Related







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