473,386 Members | 1,846 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,386 software developers and data experts.

Query related to link list

Hi
i want to know is it possible to delete the node where my
pointer currently pointing without knowing the head node address.Dis
question ask to me in an interview.

I really want to know the soloution of it.Thanx

May 17 '07 #1
5 1336
deba wrote:
Hi
i want to know is it possible to delete the node where my
pointer currently pointing without knowing the head node address.Dis
question ask to me in an interview.

I really want to know the soloution of it.Thanx
Here is the pseudocode

int node_delete(node_t **node) {

if (!node || !*node)
return -1;

//if I am last node, then free and set myself to NULL.
if (*node->next == NULL) {
free(*node);
*node = NULL;
}
else {
//if there is a node after me, copy its contents to me and free that next
//node

*node->data = *node->next->data;
*node->next = *node->next->next;
free(*node->next);
}

return 0;
}

Hope this helps.

Tejas Kokje


May 17 '07 #2
On 16 May 2007 22:18:15 -0700, deba <de**************@gmail.com>
wrote:
>Hi
i want to know is it possible to delete the node where my
pointer currently pointing without knowing the head node address.Dis
question ask to me in an interview.

I really want to know the soloution of it.Thanx
If the node you currently point to is not last, then you can copy the
next node into your node (and delete that one). This has the logical
effect of deleting the node you are pointing to but not the physical
effect (you freed a different block of memory).

If you are pointing to the last node of the list, you must somehow
have access to the next-to-last node so you can reset its "next"
pointer.
Remove del for email
May 17 '07 #3
deba wrote:
Hi
i want to know is it possible to delete the node where my
pointer currently pointing without knowing the head node address.Dis
question ask to me in an interview.

I really want to know the soloution of it.Thanx
You need to know 'here', (the current node), 'prev' (the previous node)
and 'next' (here->next).

To remove 'here' from the list logically,

prev->next = here->next;

then or course to remove it physically..

free(here), here = prev;

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
May 18 '07 #4
deba wrote:
>
i want to know is it possible to delete the node where my
pointer currently pointing without knowing the head node address.
Dis question ask to me in an interview.

I really want to know the soloution of it.Thanx
What head node address? Insufficient code.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

May 19 '07 #5
Groovy hepcat Barry Schwarz <sc******@doezl.netwas jivin' on Thu, 17 May
2007 05:19:05 -0700. It's a cool scene! Dig it.
On 16 May 2007 22:18:15 -0700, deba <de**************@gmail.comwrote:
>>Hi
i want to know is it possible to delete the node where my
pointer currently pointing without knowing the head node address.Dis
question ask to me in an interview.

I really want to know the soloution of it.Thanx

If the node you currently point to is not last, then you can copy the next
node into your node (and delete that one). This has the logical effect of
deleting the node you are pointing to but not the physical effect (you
freed a different block of memory).

If you are pointing to the last node of the list, you must somehow have
access to the next-to-last node so you can reset its "next" pointer.
Of course, it's different (simpler) for double linked lists. Since the
current node has pointers not only to the next node but also the previous
one, you simply set the next node's "previous" pointer to point at the
previous node (or set it to NULL, adjusting the "head" pointer to point at
the next node, if there is no previous node), set the previous node's
"next" pointer to point at the next node (or set it to NULL, adjusting the
"tail" pointer to point at the previous node, if there is no next node),
then remove the current node by setting its "next" and "previous" pointers
to NULL.

--
Dig the sig!

----------- Peter 'Shaggy' Haywood ------------

Ain't I'm a dawg!!
May 20 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Bruce W...1 | last post by:
I do a query to MySQL using PHP. Well actually I do too many of them which is the problem, it's too slow. I think maybe an inner join or something would be better but I can't figure this out. ...
14
by:  | last post by:
having a spot of trouble writing this one. if you are so inclined and have a moment, i'd really appreciate your insight. i have what amounts to a purchase order type of setup...a descriptive...
2
by: Larry R Harrison Jr | last post by:
The database is located at this link: http://www.angelfire.com/az/larrytucaz/tmp/db1.zip This database has a query which sometimes screens to leave out "OCB" in the last field in the query. It...
5
by: Paolo | last post by:
Friends, I have a form named Welcome on which there are various pages. On one page, simply named PAGE1, I have added a list box named LSTINITIALS, which stores the initials of my database users....
3
by: Jim Lewis | last post by:
I have read several things that state accessing a Web Service through a Query String should work. However, when I try to execute http://localhost/webservice1/service1.asmx/HelloWorld I get the...
5
by: teddysnips | last post by:
I have to write an application to do some data cleansing. It's a Contact database, but over a number of years there are multiple companies which are all essentially the same entity. For each...
7
by: BillCo | last post by:
taking the following data: a w a n b r b y b p c a getting the following result from a query:
5
by: themastertaylor | last post by:
I've got a system to manage various quotes for building materials for a number of sites. i want a query to produce a report that shows me who HASN'T quoted for which sites. basically so i can...
4
by: Doris | last post by:
It does not look like my message is posting....if this is a 2nd or 3rd message, please forgive me as I really don't know how this site works. I want to apologize ahead of time for being a novice...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.