473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Deleting a middle node from a single linked list when pointer to the previous node is

Is it possible to delete a middle node in the single linked list when the only information available we have is the pointer to the node to be deleted and not the pointer to the previous node?After deletion the previous node should point to the node next to deleted node.
Feb 12 '14 #1
2 1898
weaknessforcats
9,208 Expert Mod 8TB
Yes you can delete from the middle of the list.

The trick is to have a variable in your program that contains the address of the previous node. Usually, just as you advance to the next node you put the address of the current node inside this variable. When you are at the next node, that address will now be the previous node.

You then proceed as though this were a double-linked list.
Feb 12 '14 #2
donbock
2,426 Expert 2GB
You say "the only information available ... is the pointer to the node to be deleted and not the pointer to the previous node". In that case, you can find the pointer to the previous node by traversing the list until you find a node whose next_pointer points to the node to be deleted.

There are cases where you might want to traverse the list even if you are given pointers to both the previous node and the one to be deleted. Deleting a node that isn't in the list could corrupt the list. The criticality of the list and the potential for malicious clients will affect how much extra effort is appropriate to make the list robust.
Feb 13 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Henk | last post by:
Hi, I am new to the c-programming language and at the moment I am struggling with the following: I want to read a file using fread() and then put it in to memory. I want to use a (singel)...
11
by: sam_cit | last post by:
Hi Everyone, I want to actually reverse a single linked list without using many variables, i have a recurssive solution, but i wanted an iterative one. can anyone help me on this?
4
by: gzeng | last post by:
Is there any simple way to move the next pointer back to the beginning of a single linked list after it travers thru the list?
1
by: prasadi01 | last post by:
Hi, How can I find the 3rd last item in Single Linked List efficiently. thanks
10
by: Aditya | last post by:
Hi All, I would like to know how it is possible to insert a node in a linked list without using a temp_pointer. If the element is the first element then there is no problem but if it is in...
20
by: sirsnorklingtayo | last post by:
hi guys please help about Linked List, I'm having trouble freeing the allocated memory of a single linked list node with a dynamic char* fields, it doesn't freed up if I use the FREE()...
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.