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
ADVERTISEMENT
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
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
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
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
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
Nov 30, 2013
HelI have been tasked with creating a program which (1) takes in integer values from a user (until the user enters -1) and inputs these values into a linked list. This (2)original list is then to be printed out. The program then uses the algorithm "bubble sort" to (3)order the list in descending order before finally printing it out again.
I have managed to do this but I kind of cheated since I do not quite understand how to manipulate a linked list. What did was I took the values in the linked list and transferred them into an array and then did bubble sort on that array.how to do bubble sort on a linked list as well as how to print a linked list.
Code:
#include<stdio.h>#include<stdlib.h>
typedef struct node
{
int info;
struct node *link;
}Node, *NodePointer;
void printList (NodePointer head)
}
[code]...
View 4 Replies
View Related
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
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
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
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
Oct 30, 2014
What is the difference between BST and linked list? Or are BST implemented through linked list?
View 6 Replies
View Related
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
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
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
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
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
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
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
Jul 13, 2013
I wrote a code which checks if there are any single numbers in an array.e.g.In the next array there is a single number - "3" 4 1 4 3 4 1..Here is an array which doesn't have single numbers in it: 4 1 4 3 3 1
Code:
#include <iostream>
using namespace std;
int single (int arr[], int size)
{
int couple=0;
[Code]....
First I thought to double the number of couples I'll get from my search and find some connection to the length of the array, but it hasn't worked out (signed red).
View 9 Replies
View Related
Sep 7, 2014
I search for a really simple window library with a OpenGL context. I really only want to create window, I don't want a GUI library like wxWidgets. The best would be, if the library is cross platform compatible. In Google I only find very big libraries with widgets and other stuff.
View 4 Replies
View Related
Feb 8, 2013
There is no content when i search word in the dictionary.txt....this is my example of dictionary.txt...in the add case it is working,,only in search case...
--------------
dictionary.txt content.
--------------
mwet-asd.
test-test.
apple-prutas.
beryy-berry.
house-house.
--------------
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
using namespace std;
int counter=0;
char op;
[Code] .....
View 1 Replies
View Related
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
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
May 5, 2014
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:
This is my Node struct:
#ifndef NODE_H
#define NODE_H
#include <iostream>
template <typename T>
struct Node {
friend std::ostream &operator <<(std::ostream &os, const Node<T> &node) {
[Code] ....
The following is my set function:
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?
View 7 Replies
View Related
Sep 23, 2014
I am creating a doubly linked list that will store strings, for example:
struct node{
string data;
node* next;
node* prev;
};
node* head; //first element from left to right (global)
node* tail; // last element from left to right (global)
And here is the function:
void deleteNode(int n){
struct node* temp1 = head;
if (n == 1){
head = temp1->next;
free(temp1);
[Code] .....
View 3 Replies
View Related