473,386 Members | 1,758 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.

How to get the address of 1st node in <list>

9
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.
Expand|Select|Wrap|Line Numbers
  1.  while (temp != NULL)
  2.         {
  3.             s.push(temp);
  4.             temp = temp->next;
  5.         }
  6.  
But I am not getting address of 1st node. I tried function l1.front() which gives 1st element but not address.
Can anyone help me ?
May 16 '15 #1
3 1672
weaknessforcats
9,208 Expert Mod 8TB
If you are using front() and push() I suspect you are using an STL container.

Why would you want the address of the first node?? front() returned the element.

All those addresses are managed by the container in order to preserve the structure of the container. Letting an address escape allows some hacker guy to mess with the internals of the container and compromise the whole structure.
May 16 '15 #2
tushu
9
I want address of 1st element because " I want to push that address on to the Stack"
Because I am reversing the linklist using stack. Ones I got the 1st address , with that I will push all the remaining address's into stack with the help of above code.
And then I am going to retrieve top most address ( which will be last element's address. )
May 16 '15 #3
weaknessforcats
9,208 Expert Mod 8TB
This is the code to reverse a <list>

Expand|Select|Wrap|Line Numbers
  1. list<int> thelist;
  2.     list<int>::reverse_iterator itr;
  3.  
  4.     for (itr = thelist.rbegin(); itr != thelist.rend(); ++itr)
  5.     {
  6.  
  7.     }
You just iterate the list using a reverse iterator. When you increment a reverse iterator it backs up.

Of course you have to start at the end of the list, which is obtained by using rbegin() (right-begin) and you end at the beginning of the list, which is obtained by rend() (right-end).

The problem with pointers here is that the list container moves stuff around. So later when you get around to using your pointer, it's invalid and your program crashes.
May 16 '15 #4

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

Similar topics

10
by: Fabio | last post by:
Hi everyone, Is there anybody who can suggest me a link where I can find information about 'Persistent linked list' ? I need to implement a linked list where every node is a structure like the...
1
by: Doug | last post by:
I need to compare two "address" structures within a document, and perform some action if they are not equal. The XML document is a purchase order, with an address at both the header and line...
3
by: Mike Conmackie | last post by:
Greetings, I am trying to create a node in the output tree using a variable. Here are some fragments that I hope will explain the problem better. <xsl:stylesheet...
3
by: Miguel J. Jiménez | last post by:
Hi, I have the following node: <node> Some text here with lots of inside it... </node> and I would like it to transfrom it using XSLT to the following: Some text<br/> here with</br> lots...
2
by: fremenusul | last post by:
I orginally asked this question on friday, and made some progress, but now I am getting an error. What is the type of xmlProductName (check the runtime type in the debugger)? The debug output...
16
by: sangram | last post by:
how to delete last node of a Linked list if you only know the address of last node. thanks sangram
2
by: R.A.F. | last post by:
Hi, When i see a XML file i'm still wondering what are the differences between writing node data as node attributes or as children nodes. for example, what are the advantage to write such...
13
by: tekinalp67 | last post by:
hi, i am trying to implement a B+ tree. There is no specification in the implementation so i am using arrays to implement the B+ tree. However, there is a problem that i encountered which is I...
1
by: Jeevan83 | last post by:
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...
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:
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
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.