Remove duplicate elements: Difference between revisions

no edit summary
No edit summary
Line 2,371:
{{out}}
<pre>1 2 3 4 nan bird cat dog</pre>
 
=={{header|M2000 Interpreter}}==
Example of using a Stack object for two types, number (by default 1 is double type), and a list for fast search, append, delete. A stack object is a collection type, which we can use Push to add on top or use Data to append to bottom. A module call pass parameters to current stack, as a frame over, with the left item at the top of the stack.
 
<syntaxhighlight lang="m2000 interpreter">
Flush // current stack has no items
// Number pop a number from stack of values
// Letter pop a string from stack of values
Module TestList {
// current stack has a number, 101
// we can create a private stack
a=stack:=1, 1, "c", "d", 2, 2, 3, 3, 3, "a", "a", "b", "b"
// A list use key/values or key/Key as value. Keys can be number or strings
// Duplicate not allowed. Exist( list_type, key_to_exam) return true if key exist
// Lists are inventories types wich can't hold duplicates (error produce if append a duplicate)
// Lists have O(1) for insert, delete, search (using Hash Table)
b=list
stack a {
// replace current stack with a, old current stack kept
while not empty
if islet then // if is letter (string)
if not exist(b, stackitem$()) then Append b, letter$ else drop
else.if not exist(b, stackitem()) then
Append b, number
else
drop // drop the item
end if
end while
}
// now old current stack return as current stack
// we can sort the b list
Sort b
Print b // print the list, using right align on columns for numbers, left for strings.
Print Number=101 // true
}
TestList 101
</syntaxhighlight>
 
Actual spaces on the result line are according to column width. Here is just one space.
 
{{out}}
<pre>[1 2 3a b c d]</pre>
 
 
=={{header|Maple}}==
404

edits