C++ :: Deleting Node From End Of A List

May 5, 2013

I'M TRYING TO DELETE FROM THE END OF A LINKLIST...Actually I delete the last node but the problem is that I lost the end of the list, in other words my list leaved of pointing to NULL.I really don't know how to fixed, (it was more easy to delete from head)

Code :

void linkedstack::pop() {
if(head==NULL){
cout<<"The linklist is empty"<<endl;
return;}
else {
node *current=head;

[code]....

View 3 Replies


ADVERTISEMENT

C :: Deleting A Node From Linked List

Apr 19, 2013

I have a struct with some select student information. My wish is to be able to have the user type in a surname from the list, and for that entry to be deleted. However I am slipping up for some reason.

Here is the start of my program showing my struct:

Code:
#include <stdio.h>
#include <string.h>
#define NAME_LEN 30
#define LINE_LEN 80
struct record {

[Code] ....

I get the following errors in my while loop as well as the if statement below that loop:

-invalid operands to binary !=
-invalid type of argument '->'

View 7 Replies View Related

C++ ::  linked List - Deleting A Node

Mar 2, 2013

If p is a pointer pointing a node to be deleted, then what's wrong in the following code:

cout << "Do you want to delete this record? (y/n) ";
if (getch() == 'y' || getch() == 'Y'){// Delete record.
if (p == *ph){//If first node is to be deleted.
*ph = (*ph)->next;
delete p;

[Code] .....

View 2 Replies View Related

C++ :: Deleting Nth Node From Doubly Linked List

Sep 19, 2013

I need to delete the Nth node from a doubly linked list. I know I just cant delete it out right. I have all the goodies including a templetized node class. This is the code we're given:

template <typename T>
void doublyLinkedList<T>::deleteKthElement(const int item) {
}

It accepts an int, and should go to the Nth node and delete it.

View 1 Replies View Related

C++ :: Deleting Middle Node In Linked List

May 1, 2013

I am trying to delete a node from the end of a Linked List but I have some problems. Every node has it's unique code. Here is what I do:

1. Ask the user for the unique code of the node.
2. Ask him if he wants to change the data in it or delete the whole node.
3. If he chooses to delete it, I do this:

//let's say that temp1 points to the node
List *temp2 = temp1;
temp1 = temp1->next;
delete temp2;

And it's just not deleting the node.

View 2 Replies View Related

C++ :: Deleting Head Node In Linked List

Sep 8, 2014

I would like my function to return the data that was deleted. I have this code at the moment, where value_type is just an alias for int at the moment:

node::value_type linkedlist::removeFromHead(){
node* temp_head;
node::value_type data;
data = head_ptr->getData();

[Code] .....

When I try to use this function though, I get a segfault.

View 19 Replies View Related

C++ :: Deleting Node In BST

Nov 11, 2014

learning deleting BST node through recursion. In my class my tutor wrote something like this for BST delete node struc:

struct node{
//data
node* root, *left, *right;
}

why not

struct node{
//data
node* *left, *right;
}
node * root;

whats the difference?

View 5 Replies View Related

C :: Deleting Binary Tree Node?

Feb 18, 2014

I am having trouble with my deleteNode function, using recursion I am trying to delete a node from a binary tree. My tree is displayed as the following...

Tree: (node)->[left child, right child]
(k)->[g,p]
(g)->[c,h]
(c)->[ ,e]

[Code]....

The result did show that it is erased but when I try to add the erase node "t" back into the tree it still exist. I am stumped on what to do when using recursion way of deleting node.

View 4 Replies View Related

C++ :: Deleting Largest Node In BST Tree?

Dec 5, 2013

How would I delete the largest node in a binary search tree recursively???

View 1 Replies View Related

C++ :: Deleting Node (With Two Child) In Trees

Sep 20, 2013

I have Problems with deleting node in trees!my first problem is I don't understand the algorithm of deleting a node with two child! I write some kind of code that delete a node with two child but I think (maybe I should say I am sure ) that it has runtime or logical errors or something like that!

My second problem is my code doesn't work if my node is root of tree!because I don't know if it is root what should be the parentPtr in my code! I set parentPtr to NULL in this situation but I know it is wrong!

Here is my Code :

#include <iostream>
#include "TreeNode.h"
using namespace std;
template<typename NODETYPE> class Tree {
public:
Tree();
void insertNode(const NODETYPE &);

[Code] .....

View 3 Replies View Related

C++ :: Why Does HP / Microsoft STL List Use Same Structure For List Head And Node

Apr 23, 2013

From HP / Microsoft (Visual Studio C++) <list>:

Code:
struct _Node
{ // list node
_Genptr _Next; // successor node, or first element if head
_Genptr _Prev; // predecessor node, or last element if head
_Ty _Myval; // the stored value, unused if head
};

The stored value is wasted space for the list head. Is there any advantage to implementing list using the same structure for a list head and node?

View 6 Replies View Related

C# :: Deleting LIST From CSV?

Mar 7, 2014

Basically, I have a LIST that is saved in a CSV file, and I need to remove a particular record after using the search feature (which populates the fields from the CSV file... i.e. ID, Name, etc...).

I am able to get the details that are in the text fields by using a search feature. This is then put in:

logic.remove(tempIndividual)

In class myLogic.cs, then I have this method:

this.individual.Remove(tempIndividual)

Upon debugging, I can see that tempIndividual is populated with the correct data. However, I need to remove this data from the CSV file. Am I on the right track, or totally off? Maybe it is not complete, cause I can't get to the part where it actually removes the data from the CSV, or at least I'm not sure if .Remove is able to do it on its own.

View 9 Replies View Related

C++ :: Adding And Deleting From List

Dec 11, 2014

I am writing a program to list the 8 planets, then you select which planet you want. it gives you the mass of the planet, the radius, then you use the mass and radius of the planet to find the surface area (sphere formula) and the density of the planet. Along with those options, you have to add and delete a planet from the list and then sort them alphabetically. All i am having trouble with is the adding and deleting part. The code the adding and deleting from the list would go in cases 9 and 10.

heres my code as of this point.

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
void print(const std::string& item) {

[Code] ....

View 5 Replies View Related

C++ :: List Pointer Not Deleting?

May 30, 2013

LinkedList* listPtr = new LinkedList;

listPtr->addNode(3);
listPtr->addNode(4);
listPtr->addNode(6);
listPtr->print(std::cout);

delete listPtr;

listPtr->addNode(5);
listPtr->print(std::cout);

When I run the program it outputs
{ 3, 4, 6 }
{ 5 }

Why does the LinkedList object that listPtr is pointing to not get destroyed??

View 8 Replies View Related

C++ :: Deleting A Linked List?

Mar 27, 2014

If I have a linked list, how can I delete it at the end of my program to free the memory taken up. I know I have to use delete but not sure how to use it in this case.

Here is the code that I have:

#include <iostream>
#include <cstdlib>
using namespace std;
struct Numlist {
int num; //Number
Numlist * next; //Pointer to the next node

[code]....

View 4 Replies View Related

C/C++ :: Adding And Deleting From List

Dec 11, 2014

i am writing a program to list the 8 planets, then you select which planet you want. it gives you the mass of the planet, the radius, then you use the mass and radius of the planet to find the surface area(sphere formula) and the density of the planet. along with those options, you have to add and delete a planet from the list and then sort them alphabetically. All i am having trouble with is the adding and deleting part. the code the adding and deleting from the list would go in cases 9 and 10.

heres my code as of this point.

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
void print(const std::string& item) {

[Code] ....

View 3 Replies View Related

C++ :: Deleting Linked List Nodes Recursively

Jun 25, 2014

I am creating a Linear linked list in c++. I've written all the functions for it, but now I want to try and do them using recursion.

I managed to make functions for adding and displaying nodes on the list, but I am stuck on the function for removing nodes. First I want to try and write a function the removes the last item on the list. But for some reason my code isn't working properly.

Here is the code :

void removeLastItem(node * &head) {
if(!head) {
delete head;
head = NULL;

[Code] ....

NODE - My structure name
NEXT - The pointer to next element.
HEAD - The first (head) pointer.

The couts in the if statements are just for testing. In fact after I Run my program it does as it is supposed - enters the second if /b]case as many times as there are elements and then executes the first [b]if statement. But for some reason it does not delete the actual node.

View 2 Replies View Related

C/C++ :: Add Node In Linked List?

Dec 5, 2014

I create A program that will Add and Display the Link List but I have problem on it. If I add it will inserted in the prev node not in the next node. Here's my source code.

#include <stdio.h>
typedef struct Member {
int id;
char name[256];
struct Member *next;

[Code] ....

View 2 Replies View Related

C++ :: How To Get The Address Of 1st Node In List

May 16, 2015

Reversing Linklist using Stack. I have created linklist using <list> STL. Now I want to push address of each node in Stack. For that I want address of 1st node so that I will assign it to "temp" and I can use following loop.

HTML Code:
while (temp != NULL)
{
s.push(temp);
temp = temp->next;
}

But I am not getting address of 1st node. I tried function l1.front() which gives 1st element but not address.

View 2 Replies View Related

C :: Handling Linked List Node Add At End?

May 17, 2014

This is what I have at the moment which works as I would like but wondering if there is a better way of handling? Currently just making sure I know linked-lists well enough.

Code:

void push_to_end( node_t * headRef, int val ) {
node_t * tail = headRef;
node_t * new_node = malloc( sizeof ( node_t ));
while( headRef != NULL ) {

[Code].....

View 12 Replies View Related

C :: Linked List - Allow User To Add A New Node

Aug 12, 2013

I'm trying to impliment a simple singly linked list, then allow a user to add a new node. I have mocked up a siimple example to illustrate my point using Linked Lists...

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

[Code] ....

So I have done things similatr to this in C# and Java but not in C. There maybe some parts of this I'm sure some will disagree with in terms of buffers,overflow etc. but it's just the linked list part that I am interested in at the moment, I am only doing it like this because when it works, I will be extracting the working linked list stuff into another program that can deal with its I/O etc.

I have tried to comment as best I can to demonstarte my intentions and understandings per line of code. The add function needs to add a node of value x that the user has input, and add that to the end of the list - I'm sure that the print function is not doing all its supposed to do...

View 4 Replies View Related

C++ :: Linked List - Implementation At Nth Node

Feb 27, 2015

I have to write a program which has the user be able to enter a specific value at a specific position of the linkedlist, replacing that node with the user defined value

EX: Enter the value 5 at 2nd node, which will override the old value at the 2nd node with the new one

I am getting a compiler error which terminates my program right after the user presses the return key after he/she has given a position to change the value

Error: Unhandled exception at 0x013C50C1 in Linked(1).exe: 0xC0000005: Access violation reading location 0x0000812B.

I am not going to show the whole code as the problem resides solely on the insert function:

void TheNode::insert(double num, int choice) {
int post = 0;
MyNode *ptr = new MyNode;
(*ptr).value = num;
MyNode *previous = head;
MyNode *current = head->next;

[Code] .....

View 1 Replies View Related

C++ :: Append Node To A Linked List

Jan 27, 2013

I have a function that append node to a linked list like this:

struct ListNode{
int value;
struct ListNode* next;
};
void appendNode(struct ListNode* head, int num){

[code] ....

when I use it, the head in main() does not change its address and it's still pointing to NULL. Why??

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++ :: Linked List Remove Node

Oct 24, 2014

How to remove node from linked list. I am trying to implement this in a file record to remove data from struct..I dont know how addressing in linked list work for structs;

#include <iostream>
#include<fstream>
#include<cstring>
#include<cstdlib>

using namespace std;
struct node{
int val;

[Code] ....

segmentation fault

View 11 Replies View Related

C :: Linked List Insert Node Between Two Nodes

Oct 25, 2013

I have a problem with inserting a node between two nodes.

Code:
#include <stdio.h>
#include <stdlib.h>
struct listelem {
int nbr;
struct listelem *next;

[Code] ....

View 8 Replies View Related







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