Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I know stackoverflow has many questions like this one, but it appears that none of them are actually a solution to this.
I had a coding interview three weeks ago and one of the questions been "How do you sort an array of n people by their name in an alphabetical order ?" problem is not the answer, but Array.Sort() function was not allowed.
First thing that came in my mind was creating an array of chars of which i i can attempt to get the first char of each string from that array and store them in char[], then a nested loop to actually do the job, but after a few minutes passed this has no sense and it was or i think a wrong approach by me.
Looking in the Internet the algo that i am looking for is the Quicksort method, but this totally looks something overcomplicated, do i actually need to learn about Quicksort and replicate the algo myself or there is something less complicated that orders that array of people alphabetically ?
Exchange Sort and Bubble Sort are two quite simple sorting algorithms that can be written on the fly.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 days ago.
Improve this question
I'am making a game with unity where I will use Oxford 5000 english words and the translations in my native language and create a game focused on teaching english words to non native speakers.
I'am planning on using 2 Dictionaries each containing 5k words every word will have an ID which match the ID of their translation, Is this a correct approach? Is it ok to have 5k data in a single Dictionary?
2 Huge Dictionaries is it okay?
It depends what you mean by "okay".
If you're asking if that will crash the program, no, it won't. It will work.
But at the very least, I'd recommend keeping both words in a custom struct/class so you're not duplicating the keys in two dictionaries needlessly.
As with most programming, though, the best answer is to try it out. And if it doesn't work, fix it.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have a c# method that runs certain code blocks in a certain order. I want to pass a boolean parameter : "IsRunningInReverse" that will reverse the order in which the code blocks are run?
I could just create 2 private methods that just call the statements in normal and reverse order but I'm wondering if there is a better way to accomplish this?
I was thinking about creating delegates (Action<>) and storing them in a List and then the boolean "IsRunningInReverse" would determine whether I'd run through the list in ascending or descending order but I don't know if that's the cleanest solution.
Any input would be greatly appreciated.
Thanks!
Your solution seems fine to me.
Using Actions would be an idiomatic modern C# object wrapper for delegates, you can manipulate them easily.
To put them into a list is simple and will allow for what you want (reverse order), and even more (arbitrarily reorder them)
Maybe what might be more complicated and deserves some consideration is : would you need shared data ?
It should not be too difficult to handle this, but you would need a bit more structure (design some data sharing class for instance.
If you want to go further, once you feel more at ease with your solution, is maybe learn about expression trees .
That would be a powerful tool to manipulate different operations / actions. Beware, though, there is a large learning gap, it is quite more complicated than a List of Actions. If you simple want to reverse operations, I would still deem your List<Action> idea much more clean because it is much more simple and readable. I just thought it was worth mentioning.
How I would do it:
Make your "steps" separate functions.
Make a dictionary of the tasks and the "rank".
Then just sort asc/desc depending on what you are after.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm still learning much about immutability and when to use such objects and have started incorporating more Lookups into my coding for the fact that I knew them to be immutable and, hence, often better to use than Dictionaries that could be changed by clients.
That being said, I know there has been a good deal of work on introducing ReadOnlyDictionaries into .Net and I'm a bit confused where each would be more useful than the other and what specifically makes them different. I've looked online, but can't seem to find any articles explaining this difference.
For example, I saw this question and figured a Lookup would be a more ideal solution, but am confused as to why it wouldn't be.
Can anyone point me in the right direction / explain where either would be used over the other.
Thanks!!
Lookups are an easy way to group collections, where you could have one or more values for a given key. A Dictionary gives you one value for a give key, and one value only. Depending on your scenario, it may make most sense to have a Dictionary where you get back one value, or you may want to have a Lookup which would give you a collection of values.
Without a Lookup if you wanted a collection of values for a certain key you'd be stuck with something ugly like
Dictionary<int, IEnumerable<String>>
Yuk. See https://msdn.microsoft.com/en-us/library/bb460184%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 for more on Lookups.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am new to programming and everyone discuss about array. I have gone through array in C# and tried it in console. If someone can say me where do we exactly use array in real time software development. I know its a basic question but couldn't figure it out. Thanks in advance
You would typically use an array or a list where you have multiple instances of data with the same structure. Imaging for instance that you want to display a list of all users in your system then behind the scenes you might want to hold them as User[] users = new User[] rather than User user1, User user2, etc... It makes it a lot easier to do the same thing to (or with) each element of the list e.g.foreach(User user in users){...} than if you had to hold each entry separately.
You use arrays wherever you need to maintain lists of anything at all. For example, if I need to display a list of users in an organization, I could hold all in an array of objects.
For more information: https://en.wikipedia.org/wiki/Array_data_structure
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm going to sort 18-digit numbers like 100930200153461004, 100930200153461004 etc. It's nearly about 20K numbers to be sorted out. Which methods or ways can I use to make this happen fast. I'm using C#.net.
Thanks.
18 digit numbers should fit in a Int64. Just put them all in a List and call List.Sort().
20K numbers to sort isn't a lot really. Using the standard Sort() will already try to optimize the sorting algorithm depending on your input, no need to write your own.
There are lot of sorting methods. I would say sorting is not related to any language like C# or php, but before you implements it in any of your computer language. Have a good study of how the different sorting algorithms works. See the link - http://www.sorting-algorithms.com/
thanks