abstract-data-type

Is heap an abstract data type? If so, what about priority queues?

て烟熏妆下的殇ゞ 提交于 2019-12-22 10:53:54
问题 I read that priority queue is an abstract data type for heap data structure or to put it in another way, heap is an implementation for priority queues. But what confuses me is that I see heap in itself as an ADT since they're normally implemented using arrays (talking about min/max heaps here). Could someone give me a clear distinction among the three within the realm of ADT? 回答1: Let me answer you in two steps.. i) Defenitions Data type is a set of values together with operations on that

Implementing different yet similar structure/function sets without copy-paste

♀尐吖头ヾ 提交于 2019-12-22 04:31:31
问题 I'm implementing a set of common yet not so trivial (or error-prone) data structures for C (here) and just came with an idea that got me thinking. The question in short is, what is the best way to implement two structures that use similar algorithms but have different interfaces, without having to copy-paste/rewrite the algorithm? By best, I mean most maintainable and debug-able. I think it is obvious why you wouldn't want to have two copies of the same algorithm. Motivation Say you have a

Implementing different yet similar structure/function sets without copy-paste

老子叫甜甜 提交于 2019-12-22 04:31:02
问题 I'm implementing a set of common yet not so trivial (or error-prone) data structures for C (here) and just came with an idea that got me thinking. The question in short is, what is the best way to implement two structures that use similar algorithms but have different interfaces, without having to copy-paste/rewrite the algorithm? By best, I mean most maintainable and debug-able. I think it is obvious why you wouldn't want to have two copies of the same algorithm. Motivation Say you have a

Is 'invariant' property part of the definition of Abstraction?

别说谁变了你拦得住时间么 提交于 2019-12-21 21:27:48
问题 As part of my learning i think the best answer(with meaning) for definition of abstraction that i found is from stackoverflow: What is abstraction? Besides that, As part of current online course cs61B Fall 2006, Berkeley, i learnt the similar below definition of ADT close to above definition but added an extra word 'invariant'. Shall i consider this word as corollary to the above definition? or Is this word part of the definition? An _Abstract_Data_Type_ (ADT) is a class that has a well

OO Interface translation to Haskell

六眼飞鱼酱① 提交于 2019-12-21 04:49:11
问题 My specific problem is actually not about the general translation of an OO interface to Haskell. This is just the best title I could come up with. Yet, I'm sure that my problem originates from a still poor understanding of modeling code with Haskell and a mindset still located in the land of OO paradigms (still a haskell beginner, you see). I'm writing a Mastermind (variation) simulation to test the fitness of several Mastermind strategies. As a matter of fact, I already did that in Java and

Are there advantages to using the CUDA vector types?

你说的曾经没有我的故事 提交于 2019-12-20 10:39:14
问题 CUDA provides built-in vector data types like uint2 , uint4 and so on. Are there any advantages to using these data types? Let's assume that I have a tuple which consists of two values, A and B. One way to store them in memory is to allocate two arrays. The first array stores all the A values and the second array stores all the B values at indexes that correspond to the A values. Another way is to allocate one array of type uint2 . Which one should I use? Which way is recommended? Does

10 or 12 bit field data type in C++ [duplicate]

假如想象 提交于 2019-12-18 07:24:48
问题 This question already has an answer here : Create a 10-bit data type in C/C++ [closed] (1 answer) Closed 3 years ago . Is it possible to define some odd sized data type instead of the standard types using type-def like 10 bit or 12 bit in C++ ? 回答1: You can use a bitfield for that: struct bit_field { unsigned x: 10; // 10 bits }; and use it like bit_field b; b.x = 15; Example: #include <iostream> struct bit_field { unsigned x: 10; // 10 bits }; int main() { bit_field b; b.x = 1023; std::cout

Why use two stacks to make a queue?

不羁的心 提交于 2019-12-18 04:03:44
问题 I can see the advantage of using two stacks if an array implementation is used since stacks are more easily implemented using arrays than queues are. But if linked-lists are used, what is the advantage? The act of popping the stack onto the queue increases overhead for both linked-list and array implementations. 回答1: It's a common way to implement a queue in functional programming languages with purely functional (immutable, but sharing structure) lists (e.g. Clojure, Haskell, Erlang...): use

Why use two stacks to make a queue?

怎甘沉沦 提交于 2019-12-18 04:03:34
问题 I can see the advantage of using two stacks if an array implementation is used since stacks are more easily implemented using arrays than queues are. But if linked-lists are used, what is the advantage? The act of popping the stack onto the queue increases overhead for both linked-list and array implementations. 回答1: It's a common way to implement a queue in functional programming languages with purely functional (immutable, but sharing structure) lists (e.g. Clojure, Haskell, Erlang...): use

Inheriting abstract classes with abstract properties

亡梦爱人 提交于 2019-12-14 02:00:04
问题 I have base class with abstract properties. I want all inheriting classes to override abstract properties. Example: public class Person { public string Name{get;set;} public string LastName{get;set;} } public class Employee : Person { public string WorkPhone{get;set;} } public abstract class MyBase { public abstract Person Someone {get;set;} } public class TestClass : MyBase { public override Employee Someone{get;set;} //this is not working } Base class has Someone property with Person type.