CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2006
    Posts
    216

    Need help finding an algorithm to find a subset of an array

    I am not able to come up with an algorith for this. Please help me.
    There is an array string []arServiceNames. Let nServices be the size of this array.

    There is a structure
    struct Service
    {
    string name;
    DateTime startDateTime;
    DateTime endDateTime;
    }

    There is an array Service[]arAppointments of this structure. The elements of this array are sorted in the ascending order of startDateTime.
    I need to write a program which will find a subset of arAppointments. Let the subset be arScheduledAppointments.

    arScheduledAppointments should satisfy the following conditions:-
    1. Number of its elements = nServices
    2. arScheduledAppoinments[i].name = arServices[i] for any value of i from 0 to nServices-1
    3. The startTime of an element of this array should be equal to or more than endTime of the previous element but if it is more then the difference should be maximum 15 minutes (not more). In other words, when one service finishes then the next should start within 15 minutes.

    Let me know how to do it. Complete program is not needed. Just let me know some efficient algorithm to achieve this.
    The number of elements in arAppointments can go up to 300 but the number of elements in arServices is quite small (5 at most).
    Thanks.

  2. #2
    Join Date
    Oct 2008
    Location
    Singapore
    Posts
    195

    Re: Need help finding an algorithm to find a subset of an array

    To find a subset of an array, use Array.FindAll function like this:

    Code:
            static void Main(string[] args)
            {
    			string[] countries = new string[] {"India", "Singapore", "Canada", "USA"};
                string[] interestingOnes = Array.FindAll(countries, (country) => country.Equals("Canada"));
                foreach(string country in interestingOnes)
                {
                    Console.WriteLine(country);
                }
            }

  3. #3
    Join Date
    Oct 2006
    Posts
    216

    Re: Need help finding an algorithm to find a subset of an array

    Sorry but my question is different.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured