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
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
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:
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.
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?
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.
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.
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.
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.
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.
I dynamically allocate a new list in the recMergeSort function which should run a constructor but when it get to the functions that use it, I get error C2065: 'otherHead' : undeclared identifier. I have tried setting it to NULL and it didn't work. I even copied the default constructor to a set function and I still get the errors.
Code: template<class Type> void unorderedLinkedList<Type>::recMergeSort(nodeType<Type>* &head) { otherHead = new nodeType<Type>; if (head !=NULL) if (head->link != NULL)
[Code] ....
wonder if I'm sending the correct data type. Here is the heading of the functions that I'm using from the book.
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
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.
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.
I'm supposed to make a basic text editor using a doubly linked list, I have pretty much written most of it but keep coming across several problems. In certain places,all marked in the code, I get the error "expected a declaration" ive looked online and nothing ive found works. And secondly I also get the error" declaration has no storage class or type specifier" but i havent been able to find anything that works either.
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.
I'm trying to write a function called 'set' that sets the value of the i'th cell to val on my linkedList, and then returns the previous contents. I am stuck on it due to compiling errors:
template <typename T> T set(Node<T> *head, int i, const T &val) { for(int n = 0; n < i; n++) if(head == val) { val = i; } return val; } #endif
When I try to call it in the main() I get these errors:
node_utils.h: In function ‘T set(Node<T>*, int, const T&) [with T = int]’: node_demo.cpp:26:38: instantiated from here node_utils.h:161:2: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] node_utils.h:162:3: error: assignment of read-only reference ‘val’
So, I understand that I can't compare head & val on my if-statement -- But what do I do?
How do I Write a function that takes two linked list as input arguments these linked list contain numbers like this:
num1->3->5->2->NULL (assuming that number 1 is 352) num2->4->3->9->1->NULL (assuming that number 2 is 4391)
The function should return 1 if num1 points to a linked list which represents a smaller number than the number pointed to by num2 linked list. Otherwise, it returns -1. If both linked list point to exactly the same number, returns a 0.
My program seems to be working fine, except for when I call on my delete function. I don't receive any errors, but when I call the delete function my program outputs nothing and freezes. As in, my print function (which is called before the delete function) doesn't even work. I've tried removing bits of the function to see if I could pinpoint where exactly the issue is, but I've had no luck.
#include <iostream> #include <string> using namespace std; class List{ private: struct node{ string _data;
[Code] ....
And the function that is causing me trouble:
void deleteNode(string data){ node* del = NULL; t = h; n = h; while(n != NULL && n->_data != data){