generic-collections

generic data structure in C [duplicate]

北战南征 提交于 2021-02-07 04:00:17
问题 This question already has answers here : Simulation of templates in C (for a queue data type) (10 answers) Closed 4 years ago . Is there any way to create generic data structure in C and use functions in accordance with the stored data type, a structure that has various types of data and for example can be printed according to the stored data. For example, Suppose I wish to make a binary search tree that has just float's, int's stored. The natural approach to do would be to create an

generic data structure in C [duplicate]

随声附和 提交于 2021-02-07 03:58:32
问题 This question already has answers here : Simulation of templates in C (for a queue data type) (10 answers) Closed 4 years ago . Is there any way to create generic data structure in C and use functions in accordance with the stored data type, a structure that has various types of data and for example can be printed according to the stored data. For example, Suppose I wish to make a binary search tree that has just float's, int's stored. The natural approach to do would be to create an

generic data structure in C [duplicate]

寵の児 提交于 2021-02-07 03:57:17
问题 This question already has answers here : Simulation of templates in C (for a queue data type) (10 answers) Closed 4 years ago . Is there any way to create generic data structure in C and use functions in accordance with the stored data type, a structure that has various types of data and for example can be printed according to the stored data. For example, Suppose I wish to make a binary search tree that has just float's, int's stored. The natural approach to do would be to create an

C # equivalent of Java List<? extends Class>

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-05 06:28:45
问题 I have a basic structure of generic's classes public class Parent<T> where T : Parent<T> { Action<T> Notify; } public class Child : Parent<Child> { } And I want to have a list so that Child objects can be put there List<Parent> parents = new List<Parent>(); In java I just can write List<? extends Parent> and all Parent's subclasses easily can be added to the list. Is there any alternative of this in C#? 回答1: You can't do the same thing as Java, because in Java, generics use type erasure and

Adding non class functions to generic TArray class

和自甴很熟 提交于 2021-01-28 20:35:59
问题 In System.Generics.Collections , the TArray type has class functions only. For example: class procedure Sort<T>(var Values: array of T); overload; static; This implies the only accepted syntax is the following: var Arr : TArray<integer>; begin SetLength(Arr, 2); Arr[0] := 5; Arr[1] := 3; TArray.Sort<integer>(Arr); end; I would like to define an object's function in order to sort the values of the generic array using the following syntax: var Arr : TArray<integer>; begin SetLength(Arr, 2); Arr

Unable to convert List<List<int>> to return type IList<IList<int>>

两盒软妹~` 提交于 2020-08-19 11:42:20
问题 For level order traversal why does this exception occur? Following exception occurs: Cannot implicitly convert type ' System.Collections.Generic.List<System.Collections.Generic.List<int>> ' to ' System.Collections.Generic.IList<System.Collections.Generic.IList<int>> '. An explicit conversion exists (are you missing a cast?) public IList<IList<int>> LevelOrder(TreeNode root) { var result = new List<List<int>>(); var que = new Queue<TreeNode>(); //if(root==null) return result; que.Enqueue(root)

Unable to convert List<List<int>> to return type IList<IList<int>>

▼魔方 西西 提交于 2020-08-19 11:41:56
问题 For level order traversal why does this exception occur? Following exception occurs: Cannot implicitly convert type ' System.Collections.Generic.List<System.Collections.Generic.List<int>> ' to ' System.Collections.Generic.IList<System.Collections.Generic.IList<int>> '. An explicit conversion exists (are you missing a cast?) public IList<IList<int>> LevelOrder(TreeNode root) { var result = new List<List<int>>(); var que = new Queue<TreeNode>(); //if(root==null) return result; que.Enqueue(root)

Unable to convert List<List<int>> to return type IList<IList<int>>

♀尐吖头ヾ 提交于 2020-08-19 11:41:50
问题 For level order traversal why does this exception occur? Following exception occurs: Cannot implicitly convert type ' System.Collections.Generic.List<System.Collections.Generic.List<int>> ' to ' System.Collections.Generic.IList<System.Collections.Generic.IList<int>> '. An explicit conversion exists (are you missing a cast?) public IList<IList<int>> LevelOrder(TreeNode root) { var result = new List<List<int>>(); var que = new Queue<TreeNode>(); //if(root==null) return result; que.Enqueue(root)

How can a List<Long> references to an ArrayList which has BigInteger values

ぐ巨炮叔叔 提交于 2020-05-14 10:45:29
问题 This method is defined in a JpaRepository and runs a native PostgreSQL query. List<Long> distributorIds = distributorRepository .findDistributorIdsWithChildren(distributorId) It runs with no exception and on runtime I see BigInteger values in returned distributorIds ArrayList instead of Long values . It's same with this question: Bug in Spring Data JPA: Spring Data returns List<BigInteger> instead of List<Long> So how can this bug occur? I mean how JAVA allows this ? If Java doesn't check

Can't add keyValuePair directly to Dictionary

强颜欢笑 提交于 2020-01-10 03:27:08
问题 I wanted to add a KeyValuePair<T,U> to a Dictionary<T, U> and I couldn't. I have to pass the key and the value separately, which must mean the Add method has to create a new KeyValuePair object to insert, which can't be very efficient. I can't believe there isn't an Add(KeyValuePair<T, U>) overload on the Add method. Can anyone suggest a possible reason for this apparent oversight? 回答1: Backup a minute...before going down the road of the oversight, you should establish whether creating a new