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


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 :: 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++ ::  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++ :: 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 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++ :: Printing Powerset From Linked List?

Dec 10, 2013

I am trying to get to print a powerset from my linked list however I am not sure how to go about it. I need to create a void function for it so I know that much.

Any ways this is my code.If you do not know what a powerset is here is an example.

say you have a set {1,2,3}the power set would be the following:{{}, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}} another example say you have the power set {1,2,3,4,5} the result should be this:{{}, {1}, {2}, {3}, {4}, {5}, {1,2}, {1,3}, {1,4}, {1,5}, {2,3}, {2,4}, {2,5}, {3,4}, {3,5}, {4,5}, {1,2,3}, {1,2,4}, {1,2,5}, {1,3,4}, {1,3,5}, {1,4,5}, {2,3,4}, {2,3,5}, {2,4,5}, {3,4,5}, {1,2,3,4}, {1,2,3,5}, {1,2,4,5}, {1,3,4,5}, {2,3,4,5}, {1,2,3,4,5}}
#ifndef TEST1_H_INCLUDED
#define TEST1_H_INCLUDED
class List{

[code]....

View 5 Replies View Related

C :: Linked List Search

May 7, 2013

I read an article on linked list here: C Linked List Data Structure Explained with an Example C Program

Code:

struct test_struct* search_in_list(int val, struct test_struct **prev)
{
struct test_struct *ptr = head;
struct test_struct *tmp = NULL;
bool found = false;
}

[code].....

What is "if(prev)"? Wouldn't "prev" always have the same value? Secondly, if tmp is NULL (which will be the case when the loop if(ptr->val == val) finds a match the first time it is run), is *prev assigned a NULL?

View 1 Replies View Related

C :: Printing Info From Nodes In A Linked List

Oct 16, 2013

I created a linked list, but I wanted to make sure it was storing each word appropriately and going over the text. It compiles and runs, so I know it works. I'm just not sure if it's doing what I want...

Code:
#include <stdio.h>
#include <stdlib.h>
//creating the linked list
struct node {

[Code].....

View 3 Replies View Related

C++ :: Linked List Sorting / Splitting And Printing

Oct 3, 2014

Write a program that creates a forward linked list of at least 20 elements, where each element holds a random integer between 0 and 99. Print the list.

Write the function "returnMiddleList" to find the middle element of the linked list in one pass. Print the integer value of this element and the position of this element (starting at zero) in relation to the head (where the head = 0, the element pointed to by the head = 1, the element pointed to by the previous one = 2, etc).

Split the list in half at the middle element to create two entirely separate* linked lists of near equal size (+/- 1) and print the two lists. Modify the "returnMiddleList" function to accomplish this, returning the head of the second linked list and setting the link of the element pointing to that head to null. Then print the two sums of the integers stored in the elements of both lists.

Sort the two lists from least to greatest and print them out (printing at this step is optional depending on the sort approach taken). Then combine the two lists while sorting them again from least to greatest and print out the new list. (HINT: you can subdivide the lists further and sort them on a scale of one to two element lists before sorting and combining the first two unsorted lists. What is this sort called?)

I have got #1 and #2 working, but #3 and #4 is where the issue is beginning. When I split my link list into two lists and print the individual lists out, my first link list prints out 9 numbers when it should be printing out 10 (the 10th number somehow disappears?), but when I do the sum of the first list right after that, the number that has disappeared gets added in the sum! I do not know why it is disappearing, and this is one issue. Another issue is in the second list, a random "0" gets added to the list and one of the numbers is lost. My last issue is about #4 as the merge algorithm I have used does not seem to work (I am merging the list together while sorting them, but I am not using a recursion sort because we have not learned that yet).

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
struct nodeType {
int data;
nodeType *link;

[Code] .....

View 9 Replies View Related

C++ :: Search The Data In The Linked List?

Aug 6, 2014

How can I search the data? I want to get the output like this.

============================== Enter a data to search: 44 DATA FOUND! ==============================

Code:
#include <iostream>
using namespace std;
struct node {

[Code].....

View 1 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 :: Binary Search Tree In Linked List

Feb 25, 2014

Code:

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
struct bst {
int val, level;
struct bst *left, *right, *parent;

[Code]....

The code above is supposed to be a binary search tree. The main outcome for this program is to display the tree in C each time the user inserts or deletes a value.

Since I am a newbie in C programming, I first tried creating a code that would simply display the values in the tree after a user inserts and deletes, before I proceed to displaying the exact tree.

But when I run it the following output shows:

And when I try to insert another value, It won't display anything and won't respond to any keys pressed.

View 5 Replies View Related

C++ :: Linked List - Recursion For Search Function

Mar 19, 2013

I have a linkedList search function given and I am having a little trouble getting it to work. I've made a few attempts with no success. Given normal search code:

template <class Type>
bool orderedLinkedList<Type>::search(const Type& searchItem) const {
bool found = false;
nodeType<Type> *current; //pointer to traverse the list

current = first; //start the search at the first node

[Code] .....

My attempt to make it a recursive search:

template <class Type>
bool orderedLinkedList<Type>::search(const Type& searchItem) const {
//bool found = false;
nodeType<Type> *current; //pointer to traverse the list
current = first; //start the search at the first node

[Code] ....

View 3 Replies View Related

C/C++ :: Linked List Search Function - Find Specified Value

Feb 9, 2014

I'm have troubles with this program that requires me to make a search through a Linked List and find a specified value. It also needs to be a template function. I've completed the rest of the program fine and everything runs ok except for the search function. Code below:

Linked.h
#ifndef LINKED_H
#define LINKED_H
#include<iostream>
template <class T>
class Linked {

[Code] ....

I have commented out my attempt at the search function. When uncommenting the function I get several errors about <template> being incorrect syntax.

View 8 Replies View Related

Visual C++ :: Linked List Search Function

Feb 9, 2014

The program I have below. If you copy and paste it it should work. However, When I uncomment my search function I get lots of errors and I think it has to do with incorrect syntax of it being a template. Need to do this search function:

Linked.h header file

Code:
#ifndef LINKED_H
#define LINKED_H
#include<iostream>
template <class T>
class Linked {
private:
// Declare a structure for the list

[Code] .....

View 2 Replies View Related

C :: Simplifying A Simple Linked List With Search Function

Jun 5, 2013

Code:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

struct node
{
int data;
struct node *next;

[Code] ....

It fills the singly-linked list with 0 through 9 and calls a function to prompt the user to search for a number. I don't see any glaring errors, I was just wondering what could be done to simplify it or if there's anything I missed.

View 8 Replies View Related

C++ :: Difference Between Binary Search Tree And Linked List

Oct 30, 2014

What is the difference between BST and linked list? Or are BST implemented through linked list?

View 6 Replies View Related

C++ :: Linked List Search - Access Violation Reading Location 0xCCCCCCCC

Apr 12, 2014

I am getting an Unhandled exception at 0x00CB569E in AusitnHorton_Chapter17_7.exe: 0xC0000005: Access violation reading location 0xCCCCCCCC.

And, It puts a little yellow arrow at this line:

cout << nodepointer->value << " ";//print current node

when I try to run this program.

//Program:Make a ListNode and simple linked list class. Test the linked list class by adding varous numbers to the list and then test for membership. Then include a search function that returns the position of x on the list, if not found return -1.

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstring>
#include <fstream>
#include <cctype>
using namespace std;

class LinkedList

[Code] ....

View 3 Replies View Related

C++ :: Trying To Make Search Function In Doubly Linked List But Getting Error On Runtime

Feb 16, 2013

void search(int srch) {
if (isempty()) {
cout<<"No Record Found";
} else {
node *p;
p=head;
while(p!=NULL || p->getroll_no()==srch)

[Code] ....

View 1 Replies View Related

C++ :: Printing Each Element Of Whole String

Dec 26, 2013

Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string s="Last Assignment/n";
cout<<j[1]<<j[2]<<j[3];

I don't understand how it printing each element of whole string. Like L a s. But I did not declared array.

View 2 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







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