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

LinkedList Pointer (REPOST - diff version)



Some typo and confusion in previous post
(http://groups.google.com/group/comp....3fdc9a2d49e9ac)
made it difficult for me to fetch correct answers.
Here's the original problem.

Consider Linked List

struct node{
int data;
struct node * next;
}list;
No problem until you are dealing with a pointer variable(list).
there, you can access
memory where it is pointing to.
own address of pointer variable.
but think in case &(list->next)you can just access the target.
no clue about (atlest for me, now) what pointer comes to picture

or where it is stored.,
Description:

Consider foll. routines.

a function to add a node in the list

void Push(struct node** headRef, int newData);
Given an int and a reference to the head pointer (i.e. a struct
node** pointer to the head pointer), add a new node at the head of the
list with the standard 3-step-link-in: create the new node, set its
..next to point to the current head, and finally change the head to
point to the new node.
and a routine using it is,
void BasicsCaller() {
struct node* head;
int len;
head = BuildOneTwoThree(); // Start with {1, 2, 3}
Push(&head, 13); // Push 13 on the front,
// yielding {13, 1, 2, 3}
// (The '&' is because head is
//passed
// as a reference pointer.)
Push(&(head->next), 42); // Push 42 into the second
//position
// yielding {13, 42, 1, 2, 3}
// Demonstrates a use of '&' on
// the .next field of a node.
// (See technique #2 below.)
}

First call for push(&head,13) is obvious and works fine.
Now this is the single question:
Just explain what happens in the call Push(&(head->next), 42)
what is passed to Push and what it is done in push.
if you couldn't get me completely,
http://cslibrary.stanford.edu/105/Li...stProblems.pdf

Thanks.
Deva.

Nov 15 '05 #1
1 1482

r.*******@gmail.com wrote:
Some typo and confusion in previous post
(http://groups.google.com/group/comp....3fdc9a2d49e9ac)
made it difficult for me to fetch correct answers.
Here's the original problem.

Consider Linked List

struct node{
int data;
struct node * next;
}list;
No problem until you are dealing with a pointer variable(list).
there, you can access
>> memory where it is pointing to.
>> own address of pointer variable.
but think in case &(list->next) >>you can just access the target.
>> no clue about (atlest for me, now) what pointer comes to picture
or where it is stored.,


It contains the address of list-> next.

that is address of the field next,inside the structure pointed by list.


Description:

Consider foll. routines.

a function to add a node in the list

void Push(struct node** headRef, int newData);
Given an int and a reference to the head pointer (i.e. a struct
node** pointer to the head pointer), add a new node at the head of the
list with the standard 3-step-link-in: create the new node, set its
.next to point to the current head, and finally change the head to
point to the new node.
and a routine using it is,
void BasicsCaller() {
struct node* head;
int len;
head = BuildOneTwoThree(); // Start with {1, 2, 3}
Push(&head, 13); // Push 13 on the front,
// yielding {13, 1, 2, 3}
// (The '&' is because head is
//passed
// as a reference pointer.)
Push(&(head->next), 42); // Push 42 into the second
//position
// yielding {13, 42, 1, 2, 3}
// Demonstrates a use of '&' on
// the .next field of a node.
// (See technique #2 below.)
}

First call for push(&head,13) is obvious and works fine.
Now this is the single question:
Just explain what happens in the call Push(&(head->next), 42)
what is passed to Push and what it is done in push.
It will pass the address of next in the structure pointed by head.
Push will allocate a node,put 42 inside that.and store address of that
node in this address.

So after returning from push,head->next will contain address of newly
allocated node.


if you couldn't get me completely,
http://cslibrary.stanford.edu/105/Li...stProblems.pdf

Thanks.
Deva.


Nov 15 '05 #2

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

Similar topics

8
by: J Peterman | last post by:
Im having a nightmare trying to understand these nodes and linked lists. I've posted my code for my node.h, node.cpp, linkedlist.h and linkedlist.cpp files in separates replies. Can someone...
10
by: cody | last post by:
Why isn't there a LinkedList in .NET? Was the reason that the mark&sweep GC algorithm has problems with heavily linked data? A LinkedList is very important is you have huge lists and append a...
1
by: Spockie | last post by:
I do not use linkedlist stdlibrary, vector i make my own, but i have problems with one issue, and that is checking if there are duplicates in the middle of inputing information line 294 ...
0
by: r.devaraj | last post by:
Some typo and confusion in previous post (http://groups.google.com/group/comp.lang.c/browse_thread/thread/5e1f7437701250c4/c83fdc9a2d49e9ac?hl=en#c83fdc9a2d49e9ac) made it difficult for me to fetch...
2
by: Justin Crites | last post by:
I have an object which I want to be serializable. I have marked with with . The object only has a single data member, which is a LinkedList<int>. This linked list is a private member and cannot...
2
by: Paminu | last post by:
I am implementing a double-linkedlist in C. I have defined some pointers that points to different locations in my list. Before using the list I will initialize these pointers and when I call...
6
by: Phillip.Ross.Taylor | last post by:
When I designed my application I created an object called "Orderable" which exposes a public property "sequence". Then a few objects inherit from this. I'll just call them ObjectX for the sake...
3
by: huiling25 | last post by:
I don't know why the customer records cannot be inserted into the linked list and the head of the linked list keep pointing to null... //ListNode.java public class ListNode{ private Object...
1
by: daveftl | last post by:
' i made a type that has Element and Pointer, but this so called pointer acts like 'an index , in order to linked to the next node pointer will just increment. Option Explicit Private Type...
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: 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
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,...

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.