Results 1 to 3 of 3

Thread: Calculate address of previous element in linked list

  1. #1
    Junior Member
    Join Date
    Feb 2008
    Answers
    2

    Calculate address of previous element in linked list

    Can we calculate the address of previous element in a link list if we have the address of the current element? Can somebody suggest any method how to implement this? the only hint i have is that link elements are allocated memory from a heap.


  2. #2
    Banned
    Join Date
    Jan 2008
    Answers
    25

    Re: Calculate address of previous element in linked list

    Hi,
    If it is doubly linked list you can find the previous node address very easily like currnetNode.left().
    If it is single linked list Again you have to check from the root node.for that you have to write a loop like this.
    node=root;
    cnode=currentnode;
    while(node.next()!=cnode){
    previousnode=node;
    }


    Thanks
    --Suresh--


  3. #3
    Junior Member
    Join Date
    Feb 2008
    Answers
    2

    Unhappy Re: Calculate address of previous element in linked list

    Quote Originally Posted by sureshch83 View Post
    Hi,
    If it is doubly linked list you can find the previous node address very easily like currnetNode.left().
    If it is single linked list Again you have to check from the root node.for that you have to write a loop like this.
    node=root;
    cnode=currentnode;
    while(node.next()!=cnode){
    previousnode=node;
    }


    Thanks
    --Suresh--

    i know this can b done this way..
    but wat i was looking for is dat if i know the address of a block allocated thru(malloc or calloc or new)..is it possible to know the address of next block to b allocated...
    but i recently came to know dis is not possible in ne way

    neways thanks for the concern


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact