C/C++ :: Linked List Delete Function Freezing Program When Called

Aug 12, 2014

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){

[Code] .....

View 5 Replies


ADVERTISEMENT

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++ :: Doubly Linked List That Will Store Strings - Delete Function

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

C :: Delete A File When Function Is Called And Starts Its Loop

Apr 24, 2013

I have a function and i want to delete a file when the function is called and starts it's loop i have used this code but unfortunately the file is not deleted ?

Code:
void evaluate(void) /*evaluate the population */{
int mem;
int i;
double x[NVARS+1];
char buffer[101] = {"save.txt"};

[Code] .....

View 7 Replies View Related

C++ :: Should Delete Every Node In Linked List?

Jul 10, 2014

Still toying with my self-coded linked list class and now another question: should I delete each node of my class with the delete in the class destructor or is it done automatically when the main() function ends?

View 4 Replies View Related

C/C++ :: Delete Value At Nth Position In Linked List

Sep 30, 2014

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
struct ddpl{
string author, title, show_title, choice, user_name, borrowed_book_title, borrowed_book_author;

[Code] ....

I don't know how to do this if this was deleting by position would have been easier, but the user don't know and don't have to know the position of every book in the list it should delete the books by there title and i'm kinda lost of the delete function at line 47 and particularly at line 55 and 62, it kind difficult to traverse with the values or the data of the node for the position is simpler.

View 14 Replies View Related

C++ :: How To Delete All Values In The Linked List

Feb 15, 2012

I have made this program for linked list, but i have one problem with it. I want to make a function that will delete all same values I inuput in the list.

Example: if user inputs 5 I want to delete all 5 for the list. I have tried doing this with the loop inside regular function that erase single value.

This is function that erases single value:

Code:
void list::Delete (int a) {
node *temp=head;
if (temp==NULL)
return ;
if (temp->getNext()==NULL) {
delete temp;

[code]....

View 3 Replies View Related

C :: Delete A Node From Singly Linked List

Oct 18, 2014

I was trying to write a function in C to delete a node(only from the middle) from a Singly Linked List. I wrote one but not sure if the code will work fine under all test conditions. I have tested it and shows no error so far.

Code:
void deleteAt(struct node *root, int number){
while(root->link != NULL) {
if(root->link->item == number) //checks if the next node is the element to be deleted {
root->link = root->link->link; //points the link of the element to be deleted to the element before the element to be deleted
}
else
root = root->link;
} }

Or is there a better way to do this?

View 3 Replies View Related

C++ :: Process To Delete Everything From Single Linked List

Aug 23, 2013

what is the process to delete everything from a singly linked list. Like S= 1->2->3->... I want to remove all the values from S and reuse it again to store new datas.

View 2 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 :: List - Why Delete Function Doesn't Delete

Dec 9, 2014

I have to manage a Clinic. I need to delete a booking (for example, if John said he's coming on March 22nd at 15:30 but then he say he's not going to come, I have to delete that booking so another person can use it).

idSearched: the id of the person that is not going to come. I have a lot of specialties and each one has a list. So I ask for the speciality to delete the node (the node contains John's booking). If I don't find it, I return (-1). searchSpecByID return a pointer to the list where the speciality is. So head will point to the first node of the list. In nodeToDelete I have the node I want to delete.

The program detects OK when is the first in the list and when not, but it doesn't delete the node.

Code:

typedef struct bookingList{
tSpecialty specialty;
struct nodo* intro;
} tList;

[Code].....

View 7 Replies View Related

C++ :: Linked List Delete List?

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

C++ :: Writing Delete Algorithm In Ordered Linked List

Oct 19, 2013

I am trying to write a delete algorithm for an ordered linked list. Search and traverse I think I have down but delete is giving me fits. It crashes every time.

I have a private pointer to a ListNode strcuture called head in my TestLL class. The ListNode structure contains int Key, double dataValue, and ListNode *next. The function returns true if the node to delete was found and deleted or false if it was not found.

Code:
bool TestLL::Delete(int Key) {
ListNode *back = NULL, *temp = head;
//Search for the node to delete
while((temp != NULL) && (key != temp -> key))

[Code] .....

View 4 Replies View Related

C++ :: Singly Linked List - Delete Duplicate Nodes

Oct 10, 2014

I don't know why my code is not working. It's from line 249 - 266

void SLL::deleteDuplicate(){
Node* temp = head;
Node* p = temp;

[Code].....

View 1 Replies View Related

C/C++ :: Unable To Delete A Node In Double Linked List

Aug 22, 2014

I am trying this without a head/start pointer which would generally hold the address of first node. I have 3 nodes here from which I am trying to delete last node, but its not happening. I might be wrong in my logic and this is my first linked list program.

#include <stdio.h>
#include <stdlib.h>  
struct dll{
            struct dll *prev;
            int data;
            struct dll *next;

[Code] ....

output::::

add of p1::0x9605008 add of p2::0x9605018 add of p3::0x9605028 add of p1->prev::(nil) add of p1->next::0x9605018 add of p2->prev::0x9605008 add of p2->next::0x9605028 add of p3->prev::0x9605018 add of p3->next::(nil)

no of nodes 3

enter the addresss of node to delete it
0x9605028

after deletion attempted

add of p1::0x9605028 add of p2::0x9605018 add of p3::0x9605028 add of p1->prev::0x9605018 add of p1->next::(nil) add of p2->prev::0x9605008 add of p2->next::0x9605028 add of p3->prev::0x9605018 add of p3->next::(nil)

no of nodes 3

In this example i am trying to delete the node 3 which is p3, by deleting its address 0x9605028. But after deletion the node count is still 3 and addresses are like unexpected!

View 1 Replies View Related

C :: Delete Each Element In The List Which Is Same - Function Does Not Work Properly

Jan 18, 2014

Code:

struct lista* del(struct lista* p, char* path1) {
char model[MAX2];
int len;
char ch;
printf("Type model.

[Code] ..... t

This function should delete each element in the list which is the same as this one typed by user. There are no errors, but function doesn't work. It deletes something, but not this element which should.

View 5 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++ :: Adding Search And Delete Function To Program

Jun 21, 2013

I'm trying to add a search and delete function to my program

#include <Windows.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
using namespace std;
class Cvampire{

[Code] ....

View 4 Replies View Related

C :: Program To Manipulate Doubly Linked List

Nov 17, 2013

I'm trying to write a program that manipulates a doubly linked list. My professor wants it to have two structs, one called Node (containing the data, and pointers to the next and previous nodes) and one called DLList, which contains the nodes for the head and tail (which is then passed to all of my functions).

I'm a little confused how to access the head and tail, for instance, if I want to initially set them to null in the main function (he emphasized the need for this), or to use them in my functions. I've tried a lot of variations to call the head and tail, but I keep getting told that head and tail are undeclared in the function.

How might I access my head and tail, for instance in a main function, when they're defined like this? (I took out all of the logic in my functions for clarity)

View 1 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++ :: 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 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/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 :: Sorting A Linked List - Program Abruptly Terminates?

Nov 29, 2014

I was trying to implement sorting in a linked list. However, when i run the sortList() function the program abruptly terminates. Here's the complete code:

Code: /*
* {
* SingleLinkedList.c
*
* Created on: 28-Nov-2014

[Code].....

View 3 Replies View Related







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