Can any body help in finding the middle element of a link list in an
effective manner
i know the simple solution of using two pointers and increment one
pointer by one and second by two.
but i want a effective algo both in terms of memory and time 4 2028
On 21 Jul, 07:23, ravi <dceravigu...@gmail.comwrote:
Can any body help in finding the middle element of a link list in an
effective manner
i know the simple solution of using two pointers and increment one
pointer by one and second by two.
but i want a effective algo both in terms of memory and time
If the structure is simply a linked list, there is no quicker way to
locate the middle element than by starting at one end and moving along
one element at a time. If the structure is a doubly linked list you
could improve on the method you have suggested slightly by starting
one pointer at the front, one at the end, and seeing where they meet -
that way you only traverse the list once instead of one and a half
times.
Hope that helps.
Paul.
On Jul 22, 4:34 pm, gw7...@aol.com wrote:
On 21 Jul, 07:23, ravi <dceravigu...@gmail.comwrote:
Can any body help in finding the middle element of a link list in an
effective manner
i know the simple solution of using two pointers and increment one
pointer by one and second by two.
but i want a effective algo both in terms of memory and time
If the structure is simply a linked list, there is no quicker way to
locate the middle element than by starting at one end and moving along
one element at a time. If the structure is a doubly linked list you
could improve on the method you have suggested slightly by starting
one pointer at the front, one at the end, and seeing where they meet -
that way you only traverse the list once instead of one and a half
times.
Hope that helps.
Paul.
But how i get address of the last element of the doubly link list
for eg. i am using
struct node
{
int data;
node* next;
node *previous;
};
ravi wrote:
>
On Jul 22, 4:34 pm, gw7...@aol.com wrote:
On 21 Jul, 07:23, ravi <dceravigu...@gmail.comwrote:
If the structure is a doubly linked list you
could improve on the method you have suggested slightly by starting
one pointer at the front, one at the end,
and seeing where they meet -
that way you only traverse the list once instead of one and a half
times.
But how i get address of the last element of the doubly link list
For that matter, how do you get address of the first element?
--
pete
"ravi" <dc**********@gmail.comwrote in message
news:11**********************@g12g2000prg.googlegr oups.com...
On Jul 22, 4:34 pm, gw7...@aol.com wrote:
>On 21 Jul, 07:23, ravi <dceravigu...@gmail.comwrote:
Can any body help in finding the middle element of a link list in an
effective manner
i know the simple solution of using two pointers and increment one
pointer by one and second by two.
but i want a effective algo both in terms of memory and time
If the structure is simply a linked list, there is no quicker way to locate the middle element than by starting at one end and moving along one element at a time. If the structure is a doubly linked list you could improve on the method you have suggested slightly by starting one pointer at the front, one at the end, and seeing where they meet - that way you only traverse the list once instead of one and a half times.
Hope that helps. Paul.
But how i get address of the last element of the doubly link list
for eg. i am using
struct node
{
int data;
node* next;
node *previous;
};
The same way you get the pointer to the head of the doubly
linked list. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lawrence |
last post by:
Right now, over at www.monkeyclaus.org, the following script is
getting to the 9th run through and dying after the line:
echo "...";
You'll admit that is a strange place to die. I've hit...
|
by: DS |
last post by:
I would like to construct a frame in the middle of a page, similar to
a text box with scrollers, but I want the part in the box to be AN
html page ....
What I want to do is take a LARGE amount...
|
by: lindsey.crocker |
last post by:
I have this links list with background images set on them which changes
when they roll over.
The <td> is set valign="middle" however as soon as you apply the
rollover to the link, the text jumps...
|
by: Hi5 |
last post by:
Hi,
I am designing a database for a client in which It has a client table
including the followings:
1-Table Client
2-Table lookupcategory
3-Table Ctegory
|
by: Ian Williamson |
last post by:
Greetings,
My company has an ASP.NET based enterprise product that is undergoing some
changes and I need some community input to help solve a problem.
In the current implementation, any given...
|
by: Daniel |
last post by:
Is is possible to remove elements from the middle of a
System.Collections.Queue? For the most part i just use endqueue and dequeue
but there are points where i know that i no longer need certain...
|
by: wpollans |
last post by:
Hello,
I need to able to write JS that will click on a link with the middle
mouse button - so that the link target will open in a new window or
tab - using firefox. Or is there a better (more...
|
by: Himanshu Chauhan |
last post by:
Hi!
I was wondering, In the first parse of a singly linked list of unknown
length, is it possible to know when we are at middle of the linked list?
Regards
--Himanshu
|
by: Ben |
last post by:
Hello All:
I am new to Python, and I love it!! I am running 2.6 on Windows. I
have a flat text file here is an example of 3 lines with numbers
changed for security:
...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |