LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-16-2007, 01:27 AM   #1
Deepak Inbasekaran
Member
 
Registered: Apr 2006
Location: India
Distribution: Red Hat Linux release 9 (Shrike)
Posts: 44

Rep: Reputation: 15
Unhappy linked list traversal


i need to traverse a singly linked list only once but i should end up splitting that list into 2 linked lists with exactly half the nodes of the old one and incase of odd number of nodes, i got to add it at the end of first list itself
 
Old 05-16-2007, 12:51 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
Judging by your posting history, this is homework.

You'll get more out of your programming class if you do the work yourself.
 
Old 05-16-2007, 05:20 PM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Just to help, if your restriction is that you can only traverse the list once then the split will not be at the half way point but; first, third, fifth nodes (etc) in new list one and even nodes to new list two.

That's the design, now the coding should be a good exercise for you.
 
Old 05-16-2007, 10:33 PM   #4
Deepak Inbasekaran
Member
 
Registered: Apr 2006
Location: India
Distribution: Red Hat Linux release 9 (Shrike)
Posts: 44

Original Poster
Rep: Reputation: 15
Talking

thanks guys, anyway i worked out a logic somehow
i keep traversing the list with 2 pointers, One of them goes 2 nodes each time,the second one goes at 1 node each time till the end of the list NULL comes out
and btw am not doing any home work am working in a software company n i needed this logic for a small part of a giant code base []
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked List question (C) linuxlover1 Programming 4 03-08-2007 03:49 AM
Linked list manas_sem Programming 3 12-21-2006 01:53 AM
C linked list exvor Programming 4 04-28-2006 05:25 AM
C++ Linked List question lowpro2k3 Programming 3 06-16-2005 10:15 AM
linked list + c dilberim82 Programming 5 05-04-2005 11:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration