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


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 :: 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++ :: 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/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 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++ :: 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++ :: Employee List That Holds Information - Add Or Delete Array?

Mar 26, 2013

So I'm trying to make an employee list that holds the information so I can then delete or add from that array. I'm getting some errors regarding overloading function.

#include "employeelist.h"
const Employee & employeelist::operator [](int index) const {
return ( (this->Employees)[index] );
} Employee & employeelist::operator [](int index) {
return ( (this->Employees)[index] );

[Code] .....

View 2 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++ :: 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++ :: Delete Smallest Part Of List Of Integers To Sort In Non Decreasing Order

Mar 24, 2013

I am supposed to make a program that take a list of integers from the user and to delete the smallest part of it in order to make it sorted in non decreasing order ..

example : input : 1 2 3 4 5 8 7 6 7 8 9
output : 1 2 3 4 5 6 7 8 9 ( delete : 8 7 )

I need a code that use a technique similar to the merge function to achieve linear time ..

this code works but it is in quadratic time :

int main () {
cout<<"Enter a list of numnbers ending with the sentinel -999:"<<endl;
int A[1000];
int n = 0;
int x;
cin>>x;
while(x!=-999)

[Code] ....

View 4 Replies View Related

C++ :: How To Delete A Parameter In A Function

Apr 17, 2014

How I can delete a parameter in a function .

int *buildTrail(int antIndex, int start, double *pheromones) {
int *trail = new int[tabu];
bool *visited = new bool[tabu];
trail[0] = start;
visited[start] = true;

[Code] ....

If I comment all lines includes visited word , no exception occurs , Otherwise , exception throws.

Simply put , How can i delete visited parameter as long as its role has been finished?
.
.
.
delete visited ;
return trail;

View 4 Replies View Related

C++ :: Delete Function Not Working?

Oct 9, 2014

making my delete function work. My program does compile but my delete function doesn't work. I haven't finished my last two functions because I am focusing on the delete but how to Sell a title and print the value of all sold titles would be nice as well.

#include <iostream>
#include <cstdlib>
#include <string>

[Code].....

View 2 Replies View Related

C++ :: Binary Search Delete Function

Nov 26, 2013

I am having an issue when i try to delete a node with 2 children it either doesn't delete anything, or wigs out in various manners deleting the wrong node or replacing a node with a various memory location. As follows, here is the delete function:

void BST::dele(){
bool found = false;//initialize a bool type to "find" the element to be deleted
if(root == NULL) return;//well if the tree's empty, nothing to be found right?
current = root;//set the current to the root to traverse the tree in search of the element
node* parent;//create a parent node for use once the node has been deleted
while(current != NULL){//traverse the tree

[Code] .....

View 1 Replies View Related

C++ ::  delete Function Necessary When Allocation Fails?

Apr 13, 2014

I have a quick question about dynamic memory. I know that if you are dynamically allocating memory for a single data array and it fails, you can immediately abort the program via a return statement, but is this also true with multiple data arrays? For instance:

int *foo, *bar
foo = new (nothrow) int [5];
bar = new (nothrow) int [5];
if (foo == nullptr || bar == nullptr)
return -1;
else
/*rest of execution */

If the answer to the previous question is no, do you need to do a delete[] on the arrays that succeeded before terminating the application? Say foo is correctly allocated but bar fails, would you have to do something like this?

int *foo, *bar
foo = new (nothrow) int [5];
bar = new (nothrow) int [5];
if (foo == nullptr || bar == nullptr) {
if (foo == nullptr && bar != nullptr)
delete[] bar;

[Code] .....

View 4 Replies View Related

C :: Finding Error In Delete Node Function

Sep 12, 2013

I have written a delete node function to delete a node in a linked list by the index number. Here is the code:

Code:

void delete_node(struct node **start,int index_no)
{ int counter=0;
struct node *current=*start, *prev=NULL;//Current holds start and prev holds previous node of current
while(current->next!=NULL)

[Code]....

note that I know if the head node turns out to be the indexed position, there is no way to delete that node in the current coding. But please after correcting the present node add that part of the code separately.

View 5 Replies View Related

C :: Search And Delete Function For Binary Trees

Apr 1, 2014

I had an assignment that I completed and it was just inserting values into a binary tree and then displaying it. I was wondering what the code would be if I wanted to delete a number in the binary tree, or if I wanted to search for a number. Here is my code for my assignment.

Code:
#include <stdio.h>
#include<stdlib.h>
typedef struct bt_{
int value;
struct bt_ *right;
struct bt_ *left;

[Code] ....

View 1 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 :: 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/C++ :: How To Create Function To Delete Record Of Binary File

Aug 17, 2013

I want to create a function to Delete , Edit record of Bianry File in C++, I have tried again and gain but not success .

View 1 Replies View Related

C++ :: Delete Specified Names From A List Of Store Names?

Feb 10, 2013

i have a vector of stores. i would like to delete the specified choice(store) from the list. Here is what i have but my erase statement is wrong and wont compile.

void Store::deleteSpecifiedStoreFromList(string choice) {
for (int i = 0; i < this->stores.size(); i++) {
if(this->stores[i].getStoreNames() == choice) {
this->stores.erase( std::remove_if( this->stores.begin(), this->stores.end(), choice ), this->stores.end() );
}
}
}

View 4 Replies View Related







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