General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 9th, 2009, 12:06 PM
ndgani ndgani is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2009
Posts: 2 ndgani User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 16 sec
Reputation Power: 0
Extracting sub lists from a list

Hello to all.
i'm a real newb to this site (first post), so go easy on me please.

my problem is as follows:

given a list L of integers, i need to recursively:
while L is not an empty list
find the minimal difference d between elements in L.
remove Cd,the list of all sublists with difference d, from L.
split all subLists in Cd by length k to sublists Cd,k.

example:
L = {2,3,5,7,8,12,14,17,18,20,21,22,24,25,27}
we can see that the minimal difference is 1 and we have several subLists of different lengths
with that difference:
{2,3},{7,8},{17,18},{20,21,22},{24,25}
now removing all those sublists from L will leave it looking like this
L = {5,12,14,27}
an we start all over again

finding the minimal difference is not a problem -

public int findMinDiff(List<int> L)
{
int minDiff = L[1] - L[0];
int curr = 0;
for (int i = 0; i < L.Count - 1; i++)
{
curr = L[i + 1] - L[i];
if (curr < minDiff)
minDiff = curr;
}
return minDiff;
}

if anyone can think of a better implementation i'm all ears.

my real problem is the other two lines of psuedo-code
dividing the list to sublists and removing all the elements from the original list.

i get tangled up in while loops and recursion,ending up with an infinite loop,
so i wont post the useless code i've come up with so far.

i'm looking for an efficient way (run thru L the least number of times) to get
Cd,k and empty L.

my implementation is in c#, but that not realy relevant.

help anyone?

p.s.
i read some threads before posting my own, and a repeating question is if this is homework.
well, to save us a post and a postback, this is part of my senior year project, so you could consider it homework, but not really.

thanks.

Reply With Quote
  #2  
Old May 11th, 2009, 08:33 AM
ndgani ndgani is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2009
Posts: 2 ndgani User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 16 sec
Reputation Power: 0
thanks all.
problem sloved long ago.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Extracting sub lists from a list


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
Stay green...Green IT