如何编写这个java代码--->条目< interger,node> < ----在C#代码中 [英] How to write this java code---> entry<interger, node> <---- in C# code

查看:67
本文介绍了如何编写这个java代码--->条目< interger,node> < ----在C#代码中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Java编写这个代码(idk编程java,我知道它类似于C#),但我不知道用c#编写这个代码



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





我的尝试:



我读到这与Map.Entry有关,这是一种C#的Diccionary,但不知道如何在C#上写这个函数#div class =h2_lin>解决方案

您可以使用 SortedDictionary 类。此类公开Add方法,该方法在插入时对条目进行排序。方法复杂度O(log n)。


查看词典< TKEY的,TValue>类(System.Collections.Generic)| Microsoft Docs [ ^ ]有关如何使用它的详细信息 - 它包含示例代码。



但是翻译学生Java给学生做家庭作业C#家庭作业,我们不这样做:你不会学到任何有用的东西,对于那些试图自己理解材料的同学来说,这是不公平的......

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()) {
			keys.add(key);
			children.add(child);
		} 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#

解决方案

You can use the SortedDictionary Class. This class exposes the Add method that sorts the entry upon insertion . Method complexity O(log n).


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 ...


这篇关于如何编写这个java代码---&gt;条目&lt; interger,node&gt; &lt; ----在C#代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆