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 547111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:56:17+00:00 2026-05-13T10:56:17+00:00

I have a manager class maintaining a list of objects. Each Object has a

  • 0

I have a “manager” class maintaining a list of objects. Each Object has a certain “position”, but this is not known to them, only the manager knows about this. The manager must assign each Object a position and maintain its list of Objects sorted according to this “external attribute”.

Note that an Object’s position can change at any time. Ideally I should be able to immediately get either Element at position X or the position of Element X at any time.

This is C# code. I am wondering what would be a clean or idiomatic way of doing this.

I thought about making an internal class like this:

class SortedElement {
    public Element Elem { get; set; }
    public int Position { get; set; }
}

And then maintain a list of SortedElements. I don’t know, it seems clumsy to me. Two SortedElements could have the same Position for instance. I feel like there’s an obvious, clean solution which I’m missing. I could also make the Position a property of the Elements themselves, but it doesn’t make sense semantically, meaning there’s no reason for them to know about that except making my life easier.

Please make me go facepalm.

EDIT: Following Eric Lippert’s advice of listing my requirements, and a good night’s sleep, I realized I should opt for a LinkedList<Element> and use the index as position. Indeed, the most common operations here will be insertion at the beginning and removal anywhere within the container, which are expensive on an array-based container.
Thanks for all replies.

  • 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-13T10:56:18+00:00Added an answer on May 13, 2026 at 10:56 am

    Let’s list your requirements. I assume you want to have a data structure S which has the following operations:

    • ContainsElement: takes an element, tells you whether the element is in S
    • IsValidPosition: takes a Position, tells you whether that position is available in S
    • GetElementAt: takes a valid Position, returns an Element
    • GetPositionOf: takes an Element which is in S, returns a Position
    • InsertElementAt: takes an Element not in S and a valid Position. Puts the element at that position; all elements after that position move “up by one”.
    • RemoveElementAt: takes a valid Position, removes the element at that position, all elements after that position move “down one”.

    Is that a correct summary of the operations you want? (Note that moving an element to a new position is the same as RemoveElementAt followed by InsertElementAt.)

    If those are not a correct summary of the operations, then it would be helpful if you’d list exactly the set of operations you want your abstract data type to support.

    Once we have a clear list of requirements for operations then the next question is “what are the asymptotic performance requirements?”

    For example, you could use a List<T> as your data structure S; it supports all of those operations. However, if the list is very long then inserting and removing at the beginning of the list is very expensive, as is the “Contains” operation.

    There are more exotic data structures you can use that are highly efficient at modeling insertions and removals; we use such data structures to model changes to the state of the editor in the C# IDE. Obviously each token, variable declaration, and so on, is an “element” that has a “position” and that position changes all the time as you type around it; handling those changes in an efficient manner is quite challenging, but if that’s the sort of problem space you’re in, then describe it more clearly and we can give you pointers on data structures you can do some research on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a manager class that produces tasks for a threadpool, and each thread
I have an ASP.NET page which has a script manager on it. <form id=form1
I have a Manager class and also one frame which isReport .In the frame
I have a Manager class that saves data in the SQL table and also
I have a manager class with a number of sub-classes. I find one particular
I have a created a class that inherits from the Manager class that will
I have some event handler on a boundary class that manages a persistence mechanism
I have a manager process on a node, and several worker processes. The manager
I have a requirement to hide a process in Task Manager. It is for
I have created a one-time subscription in SSRS report manager 2008. However I keep

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.