abstract-data-type

Implementing ADT Priority Que as linked list, can't sort elements

半世苍凉 提交于 2019-12-13 04:28:30
问题 I am implementing Abstract Data Type - Priority que, but I can't find out how to put values in correct order. My structures: typedef int kintyr; typedef struct qElem { struct qElem *prv; kintyr *dat; int *priority; }qElem; typedef struct que { qElem *fr,*bk; int cnt; }que; And now my main functions to implement a Priority que First to create an empty PQ: que *qNew() { que *q = malloc(sizeof(*q)); if (q==NULL) return NULL; q->fr = NULL; q->bk = NULL; q->cnt = 0; qFault = 0; return q; } This is

Implementing a HashMap using a HashTable implementation

依然范特西╮ 提交于 2019-12-11 05:38:30
问题 I have a hashtable implementation which contains functions such as insert, remove, find, exists . Using that hashtable I wanted to implement a hashmap. So I had in mind to create a simple pair class that would just contain a key and a value. It would have the operator= overloaded to take into account only the keys equality. Also the hash function would get as input a pair object and return the hash, again taking into account only the key part. Thus I would have a hashtable<pair> inside the

Ada beginner Stack program

淺唱寂寞╮ 提交于 2019-12-11 02:14:42
问题 Basically, I have 2 files ( .adb and .ads). I am totally new to Ada and also how to compile 2 files. The program is of a basic stack implementation. I got this compile error when I compiled the .adb file. $ gcc -c test_adt_stack.adb abstract_char_stack.ads:22:01: end of file expected, file can have only one compilation unit The 2 files I have are: abstract_char_stack.ads ----------------------------------------------------------- package Abstract_Char_Stack is type Stack_Type is private;

Is it possible to emulate mixed abstract/deferred and regular procedures in Fortran 2003?

怎甘沉沦 提交于 2019-12-11 01:55:46
问题 When I try to mix both regular procedures and deferred procedures in one abstract type, gfortran balks at any invocation of the regular procedures: " Error: Base object for type-bound procedure call at (1) is of ABSTRACT type 'tbody' " type, abstract :: tBody private ... contains procedure :: init => new_Body ... procedure (contained), deferred :: PointIn end type tBody abstract interface logical(LGT) pure function contained( Body, Point ) import :: tBody, tAffinePoint, LGT class(tBody),

Java partially ordered Collection<E>

≡放荡痞女 提交于 2019-12-09 02:39:51
问题 I am looking for a Java implementation of a data structure which holds a collection of elements for which a partial ordering is defined, and which allows one to iterate over those elements in some topological order (any of the possible orderings is fine; preferably a stable ordering as the contents of the collection changes). Ideally it would implement a Collection<E> , Set<E> , or SortedSet<E> interface and support all of the methods on the interface. In terms of specifying the total

Data type in c++ or java for holding 20 digit integer

南笙酒味 提交于 2019-12-08 15:11:27
问题 Is there any data type available in Java or C++ which can hold integer values of 20 digits or more? The long long data type can hold only till 18 digits. 回答1: Java specific: You are looking for BigInteger Immutable arbitrary-precision integers. All operations behave as if BigIntegers were represented in two's-complement notation (like Java's primitive integer types) For ex: BigInteger bint = new BigInteger("1234567856656569"); BigInteger bint2 = new BigInteger("1234556567856656569"); System

Stack abstract data type in C

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 05:18:48
问题 Can you please tell me what I did wrong? I'm getting SIGSEGV (Segmentation fault) error. Is single linked list the best way to implement a stack abstract data type? I'm trying not to use global variables so that's why I used double pointers. #include <stdio.h> #include <stdlib.h> typedef struct stack{ int data; struct stack *next; }STACK; void push(STACK **head,STACK **tail,int n) { STACK *x; if(*head==NULL) { (*head)=malloc(sizeof(STACK)); (*head)->data=n; (*head)->next=NULL; *tail=*head; }

Does Fortran 2003 implementation of deferred bound procedure requires same argument?

浪尽此生 提交于 2019-12-07 17:01:08
问题 I tried to create inside a module an abstract type type, abstract :: AbsType contains procedure (Compute_AbsSize), deferred :: AbsSize end type AbsType abstract interface function Compute_AbsSize(this) import AbsType double precision Compute_AbsSize class(AbsType)::this end function Compute_AbsSize end interface type, extends(AbsType) :: ConcrType type(Var), dimension(4) :: Nodes ! coming from a module contains procedure :: AbsSize => ConcrTypeSize end type ConcrType contains function

Clojure's substitute for Haskell's ADTs and pattern matching?

微笑、不失礼 提交于 2019-12-06 17:52:51
问题 Whenever in Haskell we need some variant data type, we would use ADTs in conjunction with pattern matching. What do Clojure folks use for such use cases? 回答1: Well, there are actually some pattern matching libraries written for Clojure. Clojure's macros make this sort of thing possible. Matchure is one of the most recent. There are even some stuff for ADTs in contrib. Disregarding that stuff, the closest thing we have to Haskell's ADTs in core Clojure is the new records and datatypes in

Does Fortran 2003 implementation of deferred bound procedure requires same argument?

痴心易碎 提交于 2019-12-06 03:52:39
I tried to create inside a module an abstract type type, abstract :: AbsType contains procedure (Compute_AbsSize), deferred :: AbsSize end type AbsType abstract interface function Compute_AbsSize(this) import AbsType double precision Compute_AbsSize class(AbsType)::this end function Compute_AbsSize end interface type, extends(AbsType) :: ConcrType type(Var), dimension(4) :: Nodes ! coming from a module contains procedure :: AbsSize => ConcrTypeSize end type ConcrType contains function ConcrTypeSize(this) double precision ConcrTypeSize class (ConcrType):: this ! end function ConcrTypeSize It