Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7414679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:08:56+00:00 2026-05-29T07:08:56+00:00

I have a list List A consisted of strings {a, b, c, d, e}

  • 0

I have a list List A consisted of strings {"a", "b", "c", "d", "e"}.
My program runs in iterations and for each iteration I want to create a new list List B which is going to contain the same strings, but each of them should move to one position to the left. Here is the example of what the List B should look like in first three iterations:

  1. iteration, the List B should be: listB = {"a", "b", "c", "d", "e"}
  2. iteration, the List B should be: listB = {"b", "c", "d", "e", "a"}
  3. iteration, the List B should be: listB = {"c", "d", "e", "a", "b"}
    and so on…

I have achieved the desired functionality with the following method:

private List<string> CalculateQueueOrder(List<string> listA, int iterationNum)
{
    int listACount = listA.Count;
    List<string> listB = new List<string>();

    for (int i = 0; i < listACount; i++)
    {
        for (int j = 0; j < listACount; j++)
        {
            int order = ((j - iterationNum) % listACount + 1);
            if (order == i)
            {
                string listItem = listA[j];
                listB.Add(listItem);
                break;
            }
        }
    }
    return listB;
}

However, there is an issue with this method. In time as the number of iterations increases, the j - iterationNum starts returning negative values, which makes modulus start returning negative values as well. The whole function fails. I need to make the modulus always return the positive value, like it does in Microsofot Excel (mod function).

Could you help me out fixing the formula for int order? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:08:57+00:00Added an answer on May 29, 2026 at 7:08 am

    I achieved this here: http://rextester.com/HXACA68585

    Method is:

        private static IEnumerable<T> Cycle<T>(List<T> data, int num)
        {
            var start = num%data.Count;
            for(var i=0;i<data.Count;i++)
            {
                yield return data[(i+start)%data.Count];
            }
        }
    

    Which you can stuff back into a new list if you wanted:

    List<string> list = new List<string>(){"a", "b", "c", "d", "e"};
    List<string> newList = new List<string>(Cycle(list,2)); // contains c, d, e, a, b
    

    But to test your required results used this:

    List<string> list = new List<string>(){"a", "b", "c", "d", "e"};
    Dump(Cycle(list,0));
    Dump(Cycle(list,1));
    Dump(Cycle(list,2));
    Dump(Cycle(list,3));
    Dump(Cycle(list,4));
    Dump(Cycle(list,5));
    Dump(Cycle(list,6));
    

    Output as follows:

    a, b, c, d, e
    b, c, d, e, a
    c, d, e, a, b
    d, e, a, b, c
    e, a, b, c, d
    a, b, c, d, e
    b, c, d, e, a
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have List I want to sort Desc by Priority, which is int and
I have list of files which contain particular patterns, but those files have been
I have a list of strings and I want to convert it to checkboxes
i have list of rows that user select and i want to delete them,
I have List with n items. I wish transform my list to new list,
I have List objects which are shown like this: www.mysite.com/lists/123 Where 123 is the
I have list in python which has following entries name-1 name-2 name-3 name-4 name-1
I want to have a Dictionary that maps strings to generic lists of varying
For example if i have to create custom list view about type of food,
My input consists of user-posted strings. What I want to do is create a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.