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


ADVERTISEMENT

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++ :: 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++ :: Add / Delete And Locate Node Via Singly Linked Lists

Jul 7, 2014

I need some basic code (not for an assignment) to write an add, delete and locate an node via the singly linked list.

I've looked at: [URL] .....

View 1 Replies View Related

C :: Singly Linked List

Mar 7, 2013

I am having difficulty getting my program to run. I have looked and looked many times trying to figure out what I am doing wrong. I have a hunch that it's my load function that's acting up, but from my perspective, my creation of my singly linked list looks good. From the creation of my singly linked list, does anything stand out as being abnormal?

Code:

typedef struct Node {
char word[LENGTH+1];
struct Node *Next;
} Node;
}

[code]....

View 6 Replies View Related

C :: Add Number In Singly Linked List?

Oct 19, 2014

add number in a singly linked list? here is my code...

Code:
#include<stdio.h>
#include<stdlib.h>
struct node {

[Code].....

View 2 Replies View Related

C++ :: Singly Linked List Of Structs?

Mar 1, 2013

I want to make a singly linked list of structs with a custom datatype. Sadly, I dont think I understand either.

#include <iostream>
using namespace std;
struct datatype

[Code]....

Basically, I cant figure out how to insert a strcut with a string, random ID number, and a random salary amount, into a linked list.

View 19 Replies View Related

C/C++ :: Accept Items In Singly Linked List And Sort Nodes?

Jan 11, 2013

i want to make a program that accepts 15 items in a singly linked and sorts the nodes.

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/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++ :: Singly And Doubly Linked List - Order Inserted Elements According To Certain Pattern

Sep 13, 2014

I need to make singly and doubly linked list classes that can insert elements. Once the lists are created, I need to order the linked list elements according to a certain pattern.

order2 pattern:
input: 0 1 2 3 4 5 6 7
output: 1 0 3 2 5 4 7 6

order3 pattern:
input: 0 1 2 3 4 5 6 7 8 9 10 11
output: 2 1 0 5 4 3 8 7 6 11 10 9

sequence order pattern:
input: 0 1 2 3 4 5 6 7 8 9 10 11 12 13
output: 1 0 4 3 2 8 7 6 5 13 12 11 10 9

reverse pattern:
input: 0 1 2 3 4 5 6 7 8 9
output: 9 8 7 6 5 4 3 2 1 0

My instructor has given the description of the required classes in a file interfaces01.h as:

#pragma once
#include <cstdlib>
struct ISingleNode {
ISingleNode() {}
virtual ~ISingleNode() {}
virtual void setValue(int value) = 0;
virtual int getValue() = 0;

[Code] ....

However when I am compiling these files in vs 2013 I am getting the error: cannot open include file Singlenode.h,Singlelist.h.

Also I am not too sure about the sorting and reverse logic. How can I implement these logics.

View 1 Replies View Related

C/C++ :: Creating Singly Linked List / Loading Class Type Array

Aug 6, 2014

I've written this class and struct to create a singly linked list. The data is stored in the binary file which I've opened and read. I'm trying to load said data into a class type array. The errors I'm getting are "incompatible types in assignment of 'StatehoodInfo' to char[3]" Lines 130-134 is what I was working on.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring> //For char[] string functions

[Code] .....

View 2 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++ :: 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 :: 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/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 :: Selection Sort Algorithm For Singly Linked Lists

Feb 24, 2013

I've written code for a selection sort algorithm to sort through a singly linked list, However, it only brings the smallest node to the front, but doesnt swap positions of any of the remaining nodes, even though they are not in order.

Input list: 3 6 17 15 13 15 6 12 9 1 2 7 10 19 3 6 0 6 12 16

Sorted list: 0 6 17 15 13 15 6 12 9 1 2 7 10 19 3 6 3 6 12 16

Code:

#include<stdio.h>
#include<stdlib.h>
struct node{
int val;
struct node *next;

[Code] ......

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 :: 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 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++ :: 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







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