C++ :: Linked List Concatenation - Endless Loop
Apr 22, 2013
Having trouble with concatenating a linked list.. When I call the display function for the concatenated list, it loops endlessly?
#include <iostream>
#include <cstdlib>
using namespace std;
#ifndef Null//Null is being defined to 0 here
#define Null 0
#endif
[Code] ....
View 5 Replies
ADVERTISEMENT
Jan 14, 2015
I'm trying to get this program to return total taxi cab fair an infinite number of times, however, when I use the while statement after for and try to run the program, it just keeps displaying the first total fair rapidly.
specifications:A cab company needs a program to calculate the cost of a cab ride.
The driver will enter the length of the trip in miles.
The miles entered must be greater than 0.
Create a function to calculate the charge. The function should receive one argument, the length of the trip, and should return the total fare for the ride.
The taxi charges a fixed charge of $2.50, plus an additional charge of $1.85 per mile.
Allow the user to calculate any number of trips.
At the end display the total of all the fares.
here is my code:
#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
double getLength ();
int main () {
[code]....
View 3 Replies
View Related
Aug 29, 2013
I was trying to implement Floyd's cycle finding algorithm to find loops in linked list. I implemented my code using 2 pointers but I am not able to figure out why my output is always is 0 even though a loop exists in the code.
#include "iostream"
using namespace std;
struct Node{
[Code]....
View 5 Replies
View Related
Jan 14, 2014
I am getting and infinite loop for loop pointer variable current which points to head and is incremented by current->next in while loop. I use the pointer variable the same way in my display routine and it works. Here is listing of code.
#include "stdafx.h"
#include<iostream>
struct node{
int data;
node *next;
[Code] .....
View 1 Replies
View Related
Jun 10, 2014
I have an code that makes form window + button bet bigger when pressed each time, but it runs endless till out of screen,
code:
{
int S1 = 300;
int S2 = 0;
[Code]...
make it so it runs only each time i press the button?
View 2 Replies
View Related
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
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
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
Nov 16, 2014
After I have compiled and executed code below, and I have made an input of a string, the while loop takes over the control and outputs an endless flow sentences. How can I make sure when an input of string is made, such a thing does not happen? In Python, one can make a type check by the use of type() command, but such a command does not exist in C, so how can I prevent an endless output in case a string input is made by the user?
(The code below is supposed to check whether the number entered by the user is divisible by 7 or not.)
#include <stdio.h>
int main() {
int a = 0;
printf("Input a number!");
while (1 < 2){
scanf("%d", &a);
if (a % 7 == 0) {
[Code] ....
View 3 Replies
View Related
May 18, 2012
Why it's not working and how to make it work?
Code:
string str = "hello" + " *** ";
View 6 Replies
View Related
Jan 15, 2013
I have a question, is it possible to Concatenate a variable to a label?
For example, i'm doing:
Random Rnd = new Random();
int num1 = Rnd.Next(1, 11);
And now i want to concatenate the random number to give test me if the label of that number has a char inside.
if ( lbl_s_num1.Text != "X")
View 12 Replies
View Related
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
Sep 2, 2014
string concatenation using operator overloading function using + operator. i wrote the proto pls explain body of the function.
class A
{
char *p1,*p2;
public:
A& operator +(A &obj1)
{
-----
-----
}
};
/>
View 3 Replies
View Related
Apr 15, 2013
I have written my code, but can't seem to figure out why it doesn't enter the while loop and start asking for Input.
Code:
#include <iostream>
#include <string>
using namespace std;
int main(){
//declare variables
string cityName = "";
string stateName = "";
[Code] ....
View 3 Replies
View Related
Oct 10, 2013
I have been assigned the following task and I am having difficulty in getting it to compile. The compiler is stopping at line 27 but I don't no what the error is.
The task is as follows:
Write two functions with the following function prototypes:
int my string len(char str[])
void my string cat(char dest[], char src[], int dest size)
Both functions should take zero-terminated strings as input. The first function should return the length of the string to the calling function. The second function should take a source and a destination string and the total size of the array pointed to by dest. It should then concatenated the source string onto the end of the destination string, if and only if the destination string has the capacity to store both strings. If the destination string does not have the capacity it should not alter either, print and error, and return to the calling function. Demonstrate the use both the above functions by using them in a program in which you initialise two character arrays with two strings, print out their length, print out the combined length, and print out the combined string
And this is my code so far:
/* A program to demonstrate string concatenation */
#include <iostream>
#include <string.h>
using namespace std;
int my_string_len(char str[]){ // function to calculate length of a chracter array
int len = 0;
[Code] ....
View 8 Replies
View Related
May 15, 2013
I need to make the functions using these function prototypes. I am mainly having problems with GetFirst() and SwapData() but how to do it..
Header File with Prototypes
Code:
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
/**
* @file
* This file provided a doubly-linked list implementation capable of storing any arbitrary data.
* The list implementation relies on a chain metaphor: a list is merely a sequence of links
* (ListItems) and there is no separate construct to represent the entire list, each ListItem in it
[Code]....
View 14 Replies
View Related
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
Jan 2, 2014
I'm having a small issue here with my linked list.I built a linked list with strings and it worked perfectly.Now since i'm using strtok() to separate the string.for now here's what i've got:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct dict_word *word;
typedef struct node *Node;
typedef struct double_linked_list *DLL;
}
[code]....
View 1 Replies
View Related
Jan 6, 2014
I have the codes for the functions: "Given the functions that we have discussed and defined in the class and the code that we have created, create the code for the Delete Node function and the Search function. Create an application that will incorporate all the functions that we have discussed and the new ones that you need to create. The application should allow the linked list to be built initially from a text file. The application should then allow for the user select an operation to perform. The acceptable operations are
- to search for an item
- to delete an item
- to enter a new item
- to exit the application
After the initial build and loading of data from the textfile, the application should print a listing of each item in the list and the node that it is located in. after a delete or insert, the application should display an output of the list again showing each item in the list and the node that it resides in.
The data item for this problem will be the inventory structure that we created in class and the data is in the inventory file that you already have downloaded."
View 4 Replies
View Related
Mar 7, 2013
I am having difficulty getting my program to run. I have looked and looked many times trying to figure out what I am doing wrong. I have a hunch that it's my load function that's acting up, but from my perspective, my creation of my singly linked list looks good. From the creation of my singly linked list, does anything stand out as being abnormal?
Code:
typedef struct Node {
char word[LENGTH+1];
struct Node *Next;
} Node;
}
[code]....
View 6 Replies
View Related
Apr 2, 2013
I been ask to create a sorted linked list module, and to test each function with 1 unit, 2 +.so i wrote my addtofront function( we have to use the same as the teacher)
Code:
struct MyList{
char * name;
Sorted * AddmyChar;
struct MyList * next;
}
[code]....
but i cant seem to test it because it always display a seg fault.... i dont know what i did wrong....how do i call this function in main to display a string i want?
View 9 Replies
View Related
May 27, 2014
I decided to make a linked list program using classes and templates.I implemented my linked list and added some basic functions, everything worked just fine. Then I proceeded to add templates...First, the error list:
#pragma once
template<class T>
class Node {
private:
Node* next;
[code]....
To sum up: Something's wrong with the templates that I used in "List.cpp" and what it could be.
View 5 Replies
View Related
Jan 2, 2013
My program is almost done all that is left is entering big numbers, the program can add and subtract small numbers but not big numbers because it puts them all in one node, I need the program to store each number in a node.
#include<iostream>
#include<string>
using namespace std;
class Node {
public:
int value;
Node * next;
[Code] .....
View 11 Replies
View Related
Mar 30, 2013
When I am traversing a linked list ...i suppose we can do it only with pointers
like p is a head node pointer then
p
p->next
p->next->next
p-next->next->next
so on represents a link...
if i have to pass head node as struct variable itself...can i traverse a link using dot operator??
p and p.next and how to retrieve third and remaining links through this method if we can traverse like this???
View 1 Replies
View Related
Mar 3, 2014
I have created this program to merge two linked list into one ,but however everything is working fine but on execution it providing a segmentation fault error ( on calling merging function )
code :
#include<iostream>
#include<stdio.h>
using namespace std;
struct node{
int data;
node* link;
[code].....
View 1 Replies
View Related
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