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


ADVERTISEMENT

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++ :: 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++ :: Recursion With Linked List

Aug 28, 2013

I have a linked list I made and am practicing a simple recursion function sum() which returns the sum of all numbers in each node of the list. Here is my sum() function:

int sum(ListNode *ptr){
if (ptr->next)
return (ptr->num + sum(ptr->next));
else
return(0);
}

where the initial arg passed through the ListNode * parameter is my head node (with null value). The output is fine until that point, then the program locks up and I get the "...has stopped working" error.

View 1 Replies View Related

C/C++ :: Recursion Using Linked List

Apr 28, 2014

I have been asked to write three functions for a Liked List that can add remove and reverse the elements of the Linked List. Now, I have done the add function and It is displaying the elements properly using recursion function. But My removal function is not working and I tried all the possible logic I can think of, I dont know, where did I make mistakes.

This is My class for the Linked List

#ifndef __Linked_Lists_Recursive_function_Implementation___NumberList__
#define __Linked_Lists_Recursive_function_Implementation___NumberList__
#include <iostream>
using namespace std;

[Code]....

View 4 Replies View Related

C :: Reversal Of Doubly Linked List Using Recursion

Mar 6, 2015

I am trying to reverse a Linked list using recursion but whenever I try to print it after reversal it prints only the last element of the list.

Code:
void reverseRecursive(Node **root, Node *temp)
{
Node *next = temp->next;
if(temp->next == NULL)
{
*root = temp;

[Code]...

I have just posted the reverse function to enable easy readability rather than post the entire code

View 7 Replies View Related

C :: Reversing Linked List In Reverse Order Using Recursion

May 3, 2014

I was trying to reverse a linklist in reverse direction using the recursion. I was able to reverse n - 1 element but it is not printing the first one. Below is my code.

Code:

typedef struct linklist {
int data;
linklist *next;
};

void add(int data,linklist **node) {

[code]....

This is happening since recursion is starting from second node, which is due to reason not printing the first one when recursion print values from stack once

node != NULL

Condition is met.

Currently I am using below statement for printing the first element;

reverse_recur(node);
printf("
Print In Reverse Order
%d
",node->data);

View 6 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++ :: 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++ :: 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 :: 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++ :: 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++ :: Graph Search Algorithm - Recursion Using Stacks

Mar 22, 2013

Any example of a graph search algorithm that uses a recursion and linked list based stacks to determine a route from a single point on a graph to another single point on a graph?

View 3 Replies View Related

C++ :: Merging 2 Linked Lists Into Third One Via Recursion

Apr 17, 2012

I am having to write a program that takes 2 sorted linked lists (x and y) and merge those to sorted into a third one (z). This has to be done via recursion. I think I am close but there is a logic error.

Code:
void SortedMergeRecur(Node*& xHead,Node*& yHead,Node*& zHead)
{Node* temp = 0;
if(xHead == 0) {
zHead = yHead;
yHead = 0;
}

[Code]...

View 3 Replies View Related

C++ :: Linked List - No Matching Function

Jul 3, 2013

I have a problem with the parameters of two of my functions:

typedef List<int> Dlist;
template<class T>
Dlist concat(Dlist L1, Dlist L2) {
Dlist L;
elem<T> *temp1, *temp2;
temp1 = L1.Start_ptr;
temp2 = L1.Start_ptr;

[Code] ....

Here are the errors:
no matches converting function `concat' to type `class Dlist (*)(class List<int>, class List<int>)'
error candidates are: template<class T> Dlist concat(Dlist, Dlist)

no matching function for call to `concat(Dlist&, Dlist&)'

I can't understand what the compiler is trying to tell me.

View 4 Replies View Related

C :: Create Function That Allows Insertion Anywhere In Linked List

Feb 18, 2013

I'm trying to create a function that allows insertion anywhere in a linked list...here is what I have so far but am a bit confused on where to go from here

Code:
void llAddAtIndex(LinkedList** ll, char* value, int index) {
LinkedList* newNode = (LinkedList*)malloc(sizeof(ll));
newNode = *ll;
LinkedList* prevNode = (LinkedList*)malloc(sizeof(ll));

[Code].....

View 7 Replies View Related

C :: Delete Function In Singly Linked List

Jan 20, 2014

Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
struct node {
int data;
struct node *next;

[Code] ....

The above code is a SLL. I have a problem in my deleteNode function. I can't delete the exact data on the list. How to do this right?

View 1 Replies View Related

C :: Linked List Program Not Recognizing A Function

Oct 22, 2014

I'm writing a linked list program for class that has a simple text based menu and I believe I am nearly done, it just wont recognize my "count" function as a function and I don't know why. The error comes up at line 70.

Code:

#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int datum;
struct node *next;
} node_t;

[code]....

View 3 Replies View Related

C++ :: Sort Function For Linked List Program?

Oct 7, 2013

I'm having trouble getting my sort function to work,

void Linkedlist::sort(int num)
{
node *q;
node *a;
int input=num;

[Code].....

I get a crash and I've narrowed it down to the last if statement. Also this function is meant to handle new members after 1 member has been added.

View 7 Replies View Related

C/C++ :: Linked List Insert Item Function

Oct 14, 2014

It is suppose to insert items in Linked List in sorted ascending order and no duplicates are allowed.The code complies but it creates duplicates out of order.

ListRetVal CSortedList :: InsertItem(const ListItemType &newItem)
{
ListItemNode* newLNode = new ListItemNode();
newLNode->value=newItem;
newLNode->next=NULL;

[Code].....

View 5 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/C++ :: Add Function To Tail Of A Doubly Linked Circular List

Nov 30, 2014

I have a function that I would like to add to tail. It is not correct.

template<class T>
void DoublyLinkedCircularList<T> :: addToTail(T element) {
DoublyLinkedNode<T>* head;
DoublyLinkedNode<T>* temp;
temp->element = element;

[Code] .....

How do I fix it?

View 14 Replies View Related







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