Click here to Skip to main content
14,084,501 members
Rate this:
Please Sign up or sign in to vote.
See more:
I hava this code in Java(idk programing on java, i know its similar to C#), but i dont know to write this in c# code

public void insertSorted(Entry e, int index) {
		int key = e.getKey();
		Node child = e.getValue();
		if (index >= keys.size()) {
		} else {
			keys.add(index, key);
			children.add(index+1, child);

What I have tried:

I read that this is related to Map.Entry and this is a kind of Diccionary of C# but dont know how to write that function on C#
Updated 2 days ago
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You can use the SortedDictionary Class. This class exposes the Add method that sorts the entry upon insertion . Method complexity O(log n).
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Look at the Dictionary<TKey,TValue> Class (System.Collections.Generic) | Microsoft Docs[^] for the details on how to use it - it includes sample code.

But as for translating student Java homework to student C# homework, we don't do that: you wouldn't learn anything useful, and it wouldn't be fair on your classmates who did try to understand the material for themselves ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190518.1 | Last Updated 16 May 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100