task_url stringlengths 30 116 | task_name stringlengths 2 86 | task_description stringlengths 0 14.4k | language_url stringlengths 2 53 | language_name stringlengths 1 52 | code stringlengths 0 61.9k |
|---|---|---|---|---|---|
http://rosettacode.org/wiki/Doubly-linked_list/Element_insertion | Doubly-linked list/Element insertion | Doubly-Linked List (element)
This is much like inserting into a Singly-Linked List, but with added assignments so that the backwards-pointing links remain correct.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element inse... | #REXX | REXX | /*REXX program that implements various List Manager functions. */
/*┌────────────────────────────────────────────────────────────────────┐
┌─┘ Functions of the List Manager └─┐
│ │
│ @init ─── initi... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Delphi | Delphi |
unit main;
interface
uses
Winapi.Windows, System.SysUtils, System.Classes, Vcl.Graphics, Vcl.Forms,
Vcl.ExtCtrls;
type
TClock = class(TForm)
tmrTimer: TTimer;
procedure FormResize(Sender: TObject);
procedure tmrTimerTimer(Sender: TObject);
private
{ Private declarations }
const
... |
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #Phix | Phix | enum NEXT,PREV,DATA
constant empty_dll = {{1,1}}
sequence dll = deep_copy(empty_dll)
procedure insert_after(object data, integer pos=1)
integer prv = dll[pos][PREV]
dll = append(dll,{pos,prv,data})
if prv!=0 then
dll[prv][NEXT] = length(dll)
end if
dll[pos][PREV] = length(dll)
end procedur... |
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #PicoLisp | PicoLisp | # Print the elements a doubly-linked list
(de 2print (DLst)
(for (L (car DLst) L (cddr L))
(printsp (car L)) )
(prinl) )
# Print the elements a doubly-linked list in reverse order
(de 2printReversed (DLst)
(for (L (cdr DLst) L (cadr L))
(printsp (car L)) )
(prinl) ) |
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #Plain_English | Plain English | An element is a thing with a number. |
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #Pop11 | Pop11 | uses objectclass;
define :class Link;
slot next = [];
slot prev = [];
slot data = [];
enddefine; |
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #PureBasic | PureBasic | Structure node
*prev.node
*next.node
value.i
EndStructure |
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #Python | Python | class Node(object):
def __init__(self, data = None, prev = None, next = None):
self.prev = prev
self.next = next
self.data = data
def __str__(self):
return str(self.data)
def __repr__(self):
return repr(self.data)
def iter_forward(self):
c = self... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Julia | Julia |
const COLORS = ["red", "white", "blue"]
function dutchsort!(a::Array{ASCIIString,1}, lo=COLORS[1], hi=COLORS[end])
i = 1
j = 1
n = length(a)
while j <= n
if a[j] == lo
a[i], a[j] = a[j], a[i]
i += 1
j += 1
elseif a[j] == hi
a[j], a[n] =... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Kotlin | Kotlin | // version 1.1.4
import java.util.Random
enum class DutchColors { RED, WHITE, BLUE }
fun Array<DutchColors>.swap(i: Int, j: Int) {
val temp = this[i]
this[i] = this[j]
this[j] = temp
}
fun Array<DutchColors>.sort() {
var lo = 0
var mid = 0
var hi = this.lastIndex
while (mid <= hi) ... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #J | J | vectors =. ((% +/&.:*:"1) _1 1 0,:_1 _1 3) +/@:*"1/~ 2 3 4*=i.3
' .*o' {~ +/ 1 2 3* (|:"2 -."_ 1~ vectors) ([:*./ 1 = 0 1 I. %.~)"_ 1"_1 _ ]4j21 ,~"0/&:i: 4j41
oooo
ooooooooooooo
oooooooooooooo....
... |
http://rosettacode.org/wiki/Draw_a_pixel | Draw a pixel | Task
Create a window and draw a pixel in it, subject to the following:
the window is 320 x 240
the color of the pixel must be red (255,0,0)
the position of the pixel is x = 100, y = 100 | #True_BASIC | True BASIC | SET WINDOW 0, 320, 0, 240
SET COLOR 4
PLOT 100,100
END |
http://rosettacode.org/wiki/Draw_a_pixel | Draw a pixel | Task
Create a window and draw a pixel in it, subject to the following:
the window is 320 x 240
the color of the pixel must be red (255,0,0)
the position of the pixel is x = 100, y = 100 | #VBA | VBA | Sub draw()
Dim sh As Shape, sl As Shape
Set sh = ActiveDocument.Shapes.AddCanvas(100, 100, 320, 240)
Set sl = sh.CanvasItems.AddLine(100, 100, 101, 100)
sl.Line.ForeColor.RGB = RGB(Red:=255, Green:=0, Blue:=0)
End Sub |
http://rosettacode.org/wiki/Draw_a_rotating_cube | Draw a rotating cube | Task
Draw a rotating cube.
It should be oriented with one vertex pointing straight up, and its opposite vertex on the main diagonal (the one farthest away) straight down. It can be solid or wire-frame, and you can use ASCII art if your language doesn't have graphical capabilities. Perspective is optional.
Related ... | #TI-83_BASIC | TI-83 BASIC | :-1→Xmin:1→Xmax
:-1→Ymin:1→Ymax
:AxesOff
:Degrees
:While 1
:For(X,0,359,5
:sin(X-120→I%
:sin(X→PV
:sin(X+120→FV
:Line(0,1,I%,.3
:Line(0,1,PV,.3
:Line(0,1,FV,.3
:Line(0,-1,-I%,-.3
:Line(0,-1,-PV,-.3
:Line(0,-1,-FV,-.3
:Line(.3,I%,-.3,-PV
:Line(.3,I%,-.3,-FV
:Line(.3,PV,-.3,-I%
:Line(.3,PV,-.3,-FV
:Line(.3,FV,-.3,-I%
:Li... |
http://rosettacode.org/wiki/Draw_a_rotating_cube | Draw a rotating cube | Task
Draw a rotating cube.
It should be oriented with one vertex pointing straight up, and its opposite vertex on the main diagonal (the one farthest away) straight down. It can be solid or wire-frame, and you can use ASCII art if your language doesn't have graphical capabilities. Perspective is optional.
Related ... | #Wren | Wren | import "graphics" for Canvas, Color
import "dome" for Window
import "math" for Math
var Nodes = [
[-1, -1, -1],
[-1, -1, 1],
[-1, 1, -1],
[-1, 1, 1],
[ 1, -1, -1],
[ 1, -1, 1],
[ 1, 1, -1],
[ 1, 1, 1]
]
var Edges = [
[0, 1],
[1, 3],
[3, 2],
[2, 0],
[4, 5],... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #Befunge | Befunge | " :htpeD">:#,_&>:00p:2%10p:2/:1+1>\#<1#*-#2:#\_$:1-20p510g2*-*1+610g4vv<v<
| v%2\/3-1$_\#!4#:*#-\#1<\1+1:/4+1g00:\_\#$1<%2/2+1\g02\-1+%-g012\/-*<v"*/
_ >!>0$#0\#$\_-10p20p::00g4/:1+1>\#<1#*-#4:#\_$1-2*3/\2%!>0$#0\#$\_--vv|+2
v:\p06!*-1::p05<g00+1--g01g03\+-g01-p04+1:<0p03:-1_>>$$$1-\1->>:v:+1\<v~::
>:1+*!60g*!#v_!\!*50... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Emacs_Lisp | Emacs Lisp | ; Draw a sphere
(defun normalize (v)
"Normalize a vector."
(setq invlen (/ 1.0 (sqrt (dot v v))))
(mapcar (lambda (x) (* invlen x)) v))
(defun dot (v1 v2)
"Dot product of two vectors."
(+ (* (car v1) (car v2))
(* (cadr v1) (cadr v2))
(* (caddr v1) (caddr v2))))
(defun make-array (size)
"Crea... |
http://rosettacode.org/wiki/Doubly-linked_list/Element_insertion | Doubly-linked list/Element insertion | Doubly-Linked List (element)
This is much like inserting into a Singly-Linked List, but with added assignments so that the backwards-pointing links remain correct.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element inse... | #Ruby | Ruby | class DListNode
def insert_after(search_value, new_value)
if search_value == value
new_node = self.class.new(new_value, nil, nil)
next_node = self.succ
self.succ = new_node
new_node.prev = self
new_node.succ = next_node
next_node.prev = new_node
elsif self.succ.nil?
r... |
http://rosettacode.org/wiki/Doubly-linked_list/Element_insertion | Doubly-linked list/Element insertion | Doubly-Linked List (element)
This is much like inserting into a Singly-Linked List, but with added assignments so that the backwards-pointing links remain correct.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element inse... | #Rust | Rust | use std::collections::LinkedList;
fn main() {
let mut list = LinkedList::new();
list.push_front(8);
} |
http://rosettacode.org/wiki/Doubly-linked_list/Element_insertion | Doubly-linked list/Element insertion | Doubly-Linked List (element)
This is much like inserting into a Singly-Linked List, but with added assignments so that the backwards-pointing links remain correct.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element inse... | #Swift | Swift | typealias NodePtr<T> = UnsafeMutablePointer<Node<T>>
class Node<T> {
var value: T
fileprivate var prev: NodePtr<T>?
fileprivate var next: NodePtr<T>?
init(value: T, prev: NodePtr<T>? = nil, next: NodePtr<T>? = nil) {
self.value = value
self.prev = prev
self.next = next
}
}
@discardableResult... |
http://rosettacode.org/wiki/Doubly-linked_list/Element_insertion | Doubly-linked list/Element insertion | Doubly-Linked List (element)
This is much like inserting into a Singly-Linked List, but with added assignments so that the backwards-pointing links remain correct.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element inse... | #Tcl | Tcl | oo::define List {
method insertBefore {elem} {
$elem next [self]
$elem previous $prev
if {$prev ne ""} {
$prev next $elem
}
set prev $elem
}
method insertAfter {elem} {
$elem previous [self]
$elem next $next
if {$next ne ""} {
... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #EasyLang | EasyLang | # Clock
#
func draw hour min sec . .
# dial
color 333
move 50 50
circle 45
color 797
circle 44
color 333
for i range 60
a = i * 6
move 50 + sin a * 40 50 - cos a * 40
circle 0.25
.
for i range 12
a = i * 30
move 50 + sin a * 40 50 - cos a * 40
circle 1
.
# hour
linewid... |
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #PL.2FI | PL/I | /* To implement a doubly-linked list -- i.e., a 2-way linked list. */
doubly_linked_list: proc options (main);
define structure
1 node,
2 value fixed,
2 fwd_pointer handle(node),
2 back_pointer handle(node);
declare (head, tail, t) handle (node);
declare null builtin;
de... |
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #PureBasic | PureBasic | NewList MyData.i() ; Create a double linked list holding a single value (integer)
;Set up a randomly long linked list in the range 25-125 elements
For i=0 To (Random(100)+25)
AddElement(MyData()) ; Create a new tailing element
MyData()=Random(314) ; Inert a vale into it
Next
;
;Traverse from the beg... |
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #Racket | Racket |
(define-struct dlist (head tail) #:mutable)
(define-struct dlink (content prev next) #:mutable)
|
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #Raku | Raku | role DLElem[::T] {
has DLElem[T] $.prev is rw;
has DLElem[T] $.next is rw;
has T $.payload = T;
method pre-insert(T $payload) {
die "Can't insert before beginning" unless $!prev;
my $elem = ::?CLASS.new(:$payload);
$!prev.next = $elem;
$elem.prev = $!prev;
$elem... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Lasso | Lasso | define orderdutchflag(a) => {
local(r = array, w = array, b = array)
with i in #a do => {
match(#i) => {
case('Red')
#r->insert(#i)
case('White')
#w->insert(#i)
case('Blue')
#b->insert(#i)
}
}
return #r + #w + #b
}
orderdutchflag(array('Red', 'Red', 'Blue', 'Blue', 'Blue', 'Red', 'Red', ... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Logo | Logo | ; We'll just use words for the balls
make "colors {red white blue}
; to get a mapping from colors back to a numeric value,
; we make variables out of the color names (e.g. the variable
; "red" has value "1").
foreach arraytolist :colors [
make ? #
]
; Make a random list of a given size
to random_balls :n
local ... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Java | Java | import java.awt.*;
import java.awt.event.*;
import static java.lang.Math.*;
import javax.swing.*;
public class Cuboid extends JPanel {
double[][] nodes = {{-1, -1, -1}, {-1, -1, 1}, {-1, 1, -1}, {-1, 1, 1},
{1, -1, -1}, {1, -1, 1}, {1, 1, -1}, {1, 1, 1}};
int[][] edges = {{0, 1}, {1, 3}, {3, 2}, {2, 0},... |
http://rosettacode.org/wiki/Draw_a_pixel | Draw a pixel | Task
Create a window and draw a pixel in it, subject to the following:
the window is 320 x 240
the color of the pixel must be red (255,0,0)
the position of the pixel is x = 100, y = 100 | #Vlang | Vlang | import gg
import gx
fn main() {
mut context := gg.new_context(
width: 320
height: 240
frame_fn: frame
)
context.run()
}
fn frame(mut ctx gg.Context) {
ctx.begin()
ctx.draw_pixel(100, 100, gx.red)
ctx.end()
} |
http://rosettacode.org/wiki/Draw_a_pixel | Draw a pixel | Task
Create a window and draw a pixel in it, subject to the following:
the window is 320 x 240
the color of the pixel must be red (255,0,0)
the position of the pixel is x = 100, y = 100 | #Wee_Basic | Wee Basic | keyhide
plot 0 100,100,5
end |
http://rosettacode.org/wiki/Draw_a_rotating_cube | Draw a rotating cube | Task
Draw a rotating cube.
It should be oriented with one vertex pointing straight up, and its opposite vertex on the main diagonal (the one farthest away) straight down. It can be solid or wire-frame, and you can use ASCII art if your language doesn't have graphical capabilities. Perspective is optional.
Related ... | #XPL0 | XPL0 | def Size=100., Speed=0.05; \drawing size and rotation speed
real X, Y, Z, Farthest; \arrays: 3D coordinates of vertices
int I, J, K, ZI, Edge;
def R2=sqrt(2.), R3=sqrt(3.), R13=sqrt(1./3.), R23=sqrt(2./3.), R232=R23*2.;
\vertex:0 1 2 3 4 5 6 7
[X:... |
http://rosettacode.org/wiki/Draw_a_rotating_cube | Draw a rotating cube | Task
Draw a rotating cube.
It should be oriented with one vertex pointing straight up, and its opposite vertex on the main diagonal (the one farthest away) straight down. It can be solid or wire-frame, and you can use ASCII art if your language doesn't have graphical capabilities. Perspective is optional.
Related ... | #Yabasic | Yabasic | // Rosetta Code problem: http://rosettacode.org/wiki/Draw_a_rotating_cube
// adapted to Yabasic by Galileo, 05/2022
// GFA Punch (code from tigen.ti-fr.com/)
// Carré 3D en rotation
open window 50, 70
backcolor 0,0,0
clear window
color 255,255,255
do
clear window
x = COS(T) * 20
y = SIN(T) * 18
r = SIN(T ... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #BQN | BQN | Rot ← ¬⊸{-⌾(𝕨⊸⊑)⌽𝕩}
Turns ← {{𝕩∾1∾¬⌾((⌊2÷˜≠)⊸⊑)𝕩}⍟𝕩 ⥊1}
•Plot´ <˘⍉>+` (<0‿1)(Rot˜)`Turns 3 |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #ERRE | ERRE | PROGRAM SPHERE
CONST SHADES$=".:!*oe&#%@"
DIM LIGHT[2],X[2],Y[2],V[2],VEC[2]
PROCEDURE DOT(X[],Y[]->D)
D=X[0]*Y[0]+X[1]*Y[1]+X[2]*Y[2]
IF D<0 THEN D=-D ELSE D=0 END IF
END PROCEDURE
PROCEDURE NORMALIZE(V[]->V[])
LUNG=SQR(V[0]*V[0]+V[1]*V[1]+V[2]*V[2])
V[0]=V[0]/LUNG
V[1]=... |
http://rosettacode.org/wiki/Doubly-linked_list/Element_insertion | Doubly-linked list/Element insertion | Doubly-Linked List (element)
This is much like inserting into a Singly-Linked List, but with added assignments so that the backwards-pointing links remain correct.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element inse... | #Visual_Basic_.NET | Visual Basic .NET | Public Sub Insert(ByVal a As Node(Of T), ByVal b As Node(Of T), ByVal c As T)
Dim node As New Node(Of T)(value)
a.Next = node
node.Previous = a
b.Previous = node
node.Next = b
End Sub |
http://rosettacode.org/wiki/Doubly-linked_list/Element_insertion | Doubly-linked list/Element insertion | Doubly-Linked List (element)
This is much like inserting into a Singly-Linked List, but with added assignments so that the backwards-pointing links remain correct.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element inse... | #Wren | Wren | import "/llist" for DLinkedList
var dll = DLinkedList.new(["A", "B"])
dll.insertAfter("A", "C")
System.print(dll) |
http://rosettacode.org/wiki/Doubly-linked_list/Element_insertion | Doubly-linked list/Element insertion | Doubly-Linked List (element)
This is much like inserting into a Singly-Linked List, but with added assignments so that the backwards-pointing links remain correct.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element inse... | #Yabasic | Yabasic | // Rosetta Code problem: http://rosettacode.org/wiki/Doubly-linked_list/Element_insertion & removal & traverse
// by Galileo, 02/2022
FIL = 1 : DATO = 2 : LPREV = 3 : LNEXT = 4
countNodes = 0 : Nodes = 10
dim list(Nodes, 4)
list(0, LNEXT) = 1
sub searchNode(node)
local i, Node
for i = 0 to node-1
... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #F.23 | F# | open System.Text.RegularExpressions
let numberTemplate = """
_ _ _ _ __ _ _
/ \ /| ) _)|_||_ / /(_)(_) *
\_/ | /_ _) | _)(_) / (_) / *
"""
let g =
numberTemplate.Split([|'\n';'\r'|], System.StringSplitOptions.RemoveEmptyEntries)
|> Array.map (fun s ->
Regex.Matches(s, ".... |
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #Python | Python | class List:
def __init__(self, data, next=None, prev=None):
self.data = data
self.next = next
self.prev = prev
def append(self, data):
if self.next == None:
self.next = List(data, None, self)
return self.next
else:
return self.next.ap... |
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #Racket | Racket | (define (dlist-elements dlist)
(let loop ([elements '()] [dlink (dlist-tail dlist)])
(if dlink
(loop (cons (dlink-content dlink) elements) (dlink-prev dlink))
elements)))
(define (dlist-elements/reverse dlist)
(let loop ([elements '()] [dlink (dlist-head dlist)])
(if dlink
(loop (c... |
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #REXX | REXX | ╔═════════════════════════════════════════════════════════════════════════╗
║ ☼☼☼☼☼☼☼☼☼☼☼ Functions of the List Manager ☼☼☼☼☼☼☼☼☼☼☼ ║
║ @init ─── initializes the List. ║
║ ... |
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #Ruby | Ruby | class DListNode < ListNode
attr_accessor :prev
# accessors :succ and :value are inherited
def initialize(value, prev=nil, succ=nil)
@value = value
@prev = prev
@prev.succ = self if prev
@succ = succ
@succ.prev = self if succ
end
def self.from_values(*ary)
ary << (f = ary.pop)
a... |
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #Rust | Rust | use std::collections::LinkedList;
fn main() {
// Doubly linked list containing 32-bit integers
let list = LinkedList::<i32>::new();
} |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Lua | Lua | -- "1. Generate a randomized order of balls.."
math.randomseed(os.time())
N, balls, colors = 10, {}, { "red", "white", "blue" }
for i = 1, N do balls[i] = colors[math.random(#colors)] end
-- "..ensuring that they are not in the order of the Dutch national flag."
order = { red=1, white=2, blue=3 }
function issorted(t)
... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #JavaScript | JavaScript | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
canvas {
background-color: black;
}
</style>
</head>
<body>
<canvas></canvas>
<script>
var canvas = document.querySelector("canvas");
canvas.width = window.innerWidth;
canvas.... |
http://rosettacode.org/wiki/Draw_a_pixel | Draw a pixel | Task
Create a window and draw a pixel in it, subject to the following:
the window is 320 x 240
the color of the pixel must be red (255,0,0)
the position of the pixel is x = 100, y = 100 | #Wren | Wren | import "dome" for Window
import "graphics" for Canvas, Color
class Game {
static init() {
Window.title = "Draw a pixel"
Window.resize(320, 240)
Canvas.resize(320, 240)
var red = Color.rgb(255, 0, 0)
Canvas.pset(100, 100, red)
// check it worked
var col = Can... |
http://rosettacode.org/wiki/Draw_a_pixel | Draw a pixel | Task
Create a window and draw a pixel in it, subject to the following:
the window is 320 x 240
the color of the pixel must be red (255,0,0)
the position of the pixel is x = 100, y = 100 | #X86_Assembly | X86 Assembly |
.model tiny
.code
org 100h
start: mov ax, 0013h ;set 320x200x8 graphic screen
int 10h
push 0A000h ;point to graphic memory segment
pop es
mov byte ptr es:[320*100+100], 28h ;draw bright red pixel
mov ah, 0... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #C | C | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
/* x, y: coordinates of current point; dx, dy: direction of movement.
* Think turtle graphics. They are divided by scale, so as to keep
* very small coords/increments without losing precission. clen is
* the path length travelled, which ... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Factor | Factor | USING: classes.struct kernel raylib.ffi ;
640 480 "sphere" init-window
S{ Camera3D
{ position S{ Vector3 f 4.5 4.5 4.5 } }
{ target S{ Vector3 f 0 0 0 } }
{ up S{ Vector3 f 0 1 0 } }
{ fovy 45.0 }
{ type 0 }
}
60 set-target-fps
[ window-should-close ] [
begin-drawing
BLACK clear-... |
http://rosettacode.org/wiki/Doubly-linked_list/Element_insertion | Doubly-linked list/Element insertion | Doubly-Linked List (element)
This is much like inserting into a Singly-Linked List, but with added assignments so that the backwards-pointing links remain correct.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element inse... | #zkl | zkl | class Node{
fcn init(_value,_prev=Void,_next=Void)
{ var value=_value, prev=_prev, next=_next; }
fcn toString{ value.toString() }
fcn append(value){
b,c := Node(value,self,next),next;
next=b;
if(c) c.prev=b;
b
}
} |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Forth | Forth |
HEX
8379 CONSTANT TICKER \ address of 1/60 second counter
CREATE PDT ( -- addr) \ bit pattern descriptors for 0..9 and colon
0038 , 444C , 5464 , 4438 , ( 0)
0010 , 3010 , 1010 , 1038 , ( 1)
0038 , 4404 , 1820 , 407C , ( 2)
007C , 0810 , 0804 , 4438 , ( 3)
0008 , 1828 , 487... |
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #Raku | Raku | say $dll.list;
say $dll.reverse; |
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #REXX | REXX | /*REXX program that implements various List Manager functions. */
/*┌────────────────────────────────────────────────────────────────────┐
┌─┘ Functions of the List Manager └─┐
│ │
│ @init ─── initi... |
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #Sidef | Sidef | var node = Hash.new(
data => 'say what',
next => foo_node,
prev => bar_node,
);
node{:next} = quux_node; # mutable |
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #Swift | Swift | typealias NodePtr<T> = UnsafeMutablePointer<Node<T>>
class Node<T> {
var value: T
fileprivate var prev: NodePtr<T>?
fileprivate var next: NodePtr<T>?
init(value: T, prev: NodePtr<T>? = nil, next: NodePtr<T>? = nil) {
self.value = value
self.prev = prev
self.next = next
}
}
|
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #Tcl | Tcl | oo::class create List {
variable content next prev
constructor {value {list ""}} {
set content $value
set next $list
set prev ""
if {$next ne ""} {
$next previous [self]
}
}
method value args {
set content {*}$args
}
method next args {
... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #M2000_Interpreter | M2000 Interpreter |
Report "Dutch Flag from Dijkstra"
const center=2
enum balls {Red, White, Blue}
fillarray=lambda a=(Red, White, Blue) (size as long=10)-> {
if size<1 then size=1
randomitem=lambda a->a#val(random(0,2))
dim a(size)<<randomitem()
=a()
}
Display$=lambda$ (s as array) ->{
Document r$=eval$(array(s))
... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | flagSort[data_List] := Sort[data, (#1 === RED || #2 === BLUE) &] |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Julia | Julia | _pr(t::Dict, x::Int, y::Int, z::Int) = join((rstrip(join(t[(n, m)] for n in range(0, 3+x+z))) for m in reverse(range(0, 3+y+z))), "\n")
function cuboid(x::Int, y::Int, z::Int)
t = Dict((n, m) => " " for n in range(0, 3 + x + z), m in range(0, 3 + y + z))
xrow = vcat("+", collect("$(i % 10)" for i in range(0, ... |
http://rosettacode.org/wiki/Draw_a_pixel | Draw a pixel | Task
Create a window and draw a pixel in it, subject to the following:
the window is 320 x 240
the color of the pixel must be red (255,0,0)
the position of the pixel is x = 100, y = 100 | #XPL0 | XPL0 | [SetFB(320, 240, 24); Point(100, 100, $FF0000)] |
http://rosettacode.org/wiki/Draw_a_pixel | Draw a pixel | Task
Create a window and draw a pixel in it, subject to the following:
the window is 320 x 240
the color of the pixel must be red (255,0,0)
the position of the pixel is x = 100, y = 100 | #Yabasic | Yabasic | open window 320, 240
color 255, 0, 0
dot 100, 100 |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #C.23 | C# | using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
public class DragonCurve : Form
{
private List<int> turns;
private double startingAngle, side;
public DragonCurve(int iter)
{
Size = new Size(800, 600);
S... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Forth | Forth | : 3dup 2 pick 2 pick 2 pick ;
: sqrt ( u -- sqrt ) ( Babylonian method )
dup 2/ ( first square root guess is half )
dup 0= if drop exit then ( sqrt[0]=0, sqrt[1]=1 )
begin dup >r 2dup / r> + 2/ ( stack: square old-guess new-guess )
2dup >... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Fortran | Fortran |
!Digital Text implemented as in C version - Anant Dixit (Oct, 2014)
program clock
implicit none
integer :: t(8)
do
call date_and_time(values=t)
call sleep(1)
call system('clear')
call digital_display(t(5),t(6),t(7))
end do
end program
subroutine digital_display(H,M,S)
!arguments
integer :: H, M, S
!local
ch... |
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #Ring | Ring |
# Project : Doubly-linked list/Traversal
trav = [123, 789, 456]
travfor = sort(trav)
see "Traverse forwards:" + nl
see travfor
see nl
travback = reverse(travfor)
see "Traverse backwards:" + nl
see travback
see nl
|
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #Ruby | Ruby | class DListNode
def get_tail
# parent class (ListNode) includes Enumerable, so the find method is available to us
self.find {|node| node.succ.nil?}
end
def each_previous(&b)
yield self
self.prev.each_previous(&b) if self.prev
end
end
head = DListNode.from_array([:a, :b, :c])
head.each {|node... |
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #Visual_Basic_.NET | Visual Basic .NET | Public Class Node(Of T)
Public Value As T
Public [Next] As Node(Of T)
Public Previous As Node(Of T)
End Class |
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #Wren | Wren | import "/llist" for DNode
var dn1 = DNode.new(1)
var dn2 = DNode.new(2)
dn1.next = dn2
dn1.prev = null
dn2.prev = dn1
dn2.next = null
System.print(["node 1", "data = %(dn1.data)", "prev = %(dn1.prev)", "next = %(dn1.next)"])
System.print(["node 2", "data = %(dn2.data)", "prev = %(dn2.prev)", "next = %(dn2.next)"]) |
http://rosettacode.org/wiki/Doubly-linked_list/Element_definition | Doubly-linked list/Element definition | Task
Define the data structure for a doubly-linked list element.
The element should include a data member to hold its value and pointers to both the next element in the list and the previous element in the list.
The pointers should be mutable.
See also
Array
Associative array: Creation, Iteration
Collections
... | #zkl | zkl | class Node{
fcn init(_value,_prev=Void,_next=Void)
{ var value=_value, prev=_prev, next=_next; }
fcn toString{ value.toString() }
} |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Nim | Nim | import os, random, strutils
type Color {.pure.} = enum Red = "R", White = "W", Blue = "B"
#---------------------------------------------------------------------------------------------------
proc isSorted(a: openArray[Color]): bool =
# Check if an array of colors is in the order of the dutch national flag.
va... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #PARI.2FGP | PARI/GP | compare(a,b)={
if (a==b,
0
,
if(a=="red" || b=="blue", -1, 1)
)
};
r(n)=vector(n,i,if(random(3),if(random(2),"red","white"),"blue"));
inorder(v)=for(i=2,#v,if(compare(v[i-1],v[i])>0,return(0)));1;
v=r(10);
while(inorder(v), v=r(10));
v=vecsort(v,compare);
inorder(v) |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Kotlin | Kotlin | // version 1.1
import java.awt.*
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import javax.swing.*
class Cuboid: JPanel() {
private val nodes = arrayOf(
doubleArrayOf(-1.0, -1.0, -1.0),
doubleArrayOf(-1.0, -1.0, 1.0),
doubleArrayOf(-1.0, 1.0, -1.0),
doubl... |
http://rosettacode.org/wiki/Draw_a_pixel | Draw a pixel | Task
Create a window and draw a pixel in it, subject to the following:
the window is 320 x 240
the color of the pixel must be red (255,0,0)
the position of the pixel is x = 100, y = 100 | #ZX_Spectrum_Basic | ZX Spectrum Basic | PLOT INK 2;100,100 |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #C.2B.2B | C++ |
#include <windows.h>
#include <iostream>
//-----------------------------------------------------------------------------------------
using namespace std;
//-----------------------------------------------------------------------------------------
const int BMP_SIZE = 800, NORTH = 1, EAST = 2, SOUTH = 4, WEST = 8, ... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Frink | Frink | res = 254 / in
v = callJava["frink.graphics.VoxelArray", "makeSphere", [1/2 inch res]]
v.projectX[undef].show["X"]
v.projectY[undef].show["Y"]
v.projectZ[undef].show["Z"]
filename = "sphere.stl"
print["Writing $filename..."]
w = new Writer[filename]
w.println[v.toSTLFormat["sphere", 1/(res mm)]]
w.close[]
printl... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #FreeBASIC | FreeBASIC | ' version 05-04-2017
' compile with: fbc -s gui
Const As Double deg2rad = Atn(1) / 45
Const As UInteger w = 199, h = 199
Const As UInteger x0 = w \ 2, y0 = h \ 2 ' center
Dim As UInteger x, x1, x2, x3, y, y1, y2, y3
Dim As String sys_time, press
Dim As Integer hours, minutes, seconds
Dim As Double angle, a_sin, a_c... |
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #Salmon | Salmon | class item(init_data)
{
variable next,
previous,
data := init_data;
};
function prepend(tail, new_data)
{
immutable result := item(new_data);
result.next := tail;
result.previous := null;
if (tail != null)
tail.previous := result;;
return result;
};
... |
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #Scala | Scala | import java.util
object DoublyLinkedListTraversal extends App {
private val ll = new util.LinkedList[String]
private def traverse(iter: util.Iterator[String]) =
while (iter.hasNext) iter.next
traverse(ll.iterator)
traverse(ll.descendingIterator)
} |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Perl | Perl | use warnings;
use strict;
use 5.010; # //
use List::Util qw( shuffle );
my @colours = qw( blue white red );
sub are_ordered {
my $balls = shift;
my $last = 0;
for my $ball (@$balls) {
return if $ball < $last;
$last = $ball;
}
return 1;
}
sub show {
my $balls = shift;
... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Liberty_BASIC | Liberty BASIC |
Call cuboid 1,3,4
End
Sub cuboid width, height, depth
wd=width*7+2: hi=height*3: dp=depth
For i=1 To wd-2
w$=w$+"-":h$=h$+" "
Next
w$="+"+w$+"+":d$="/"+h$+"/":h$="|"+h$+"|"
px=dp+2:py=1:Locate dp+2,py:Print w$;
For i=2 To hi+1
Locate wd+dp+1,i:Print"|";
Next
Locate ... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #COBOL | COBOL | >>SOURCE FORMAT FREE
*> This code is dedicated to the public domain
identification division.
program-id. dragon.
environment division.
configuration section.
repository. function all intrinsic.
data division.
working-storage section.
01 segment-length pic 9 value 2.
01 mark pic x value '.'.
01 segment-count... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #FutureBasic | FutureBasic |
include "Tlbx agl.incl"
include "Tlbx glut.incl"
output file "Rotating Sphere"
local fn SphereDraw
'~'1
begin globals
dim as double sRotation // 'static' var
end globals
// Speed of rotation
sRotation += 2.9
glMatrixMode( _GLMODELVIEW )
glLoadIdentity()
// Position parameters: x axis, y axis, z axis
// Set... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #FunL | FunL | import concurrent.{scheduleAtFixedRate, scheduler}
val ROW = 10
val COL = 20
val digits = array( [
" __",
" / /",
"/__/ ",
" ",
" /",
" / ",
" __",
" __/",
"/__ ",
" __",
" __/",
" __/ ",
" ",
" /__/",
" / ",
" __",
" /__ ",
" __/ ",
" __",
" /__ ",... |
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #Tcl | Tcl | # Modify the List class to add the iterator methods
oo::define List {
method foreach {varName script} {
upvar 1 $varName v
for {set node [self]} {$node ne ""} {set node [$node next]} {
set v [$node value]
uplevel 1 $script
}
}
method revforeach {varName script... |
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #Wren | Wren | import "/llist" for DLinkedList
import "/fmt" for Fmt
// create a new doubly-linked list and add the first 50 positive integers to it
var dll = DLinkedList.new(1..50)
// traverse the doubly-linked list from head to tail
for (i in dll) {
Fmt.write("$4d ", i)
if (i % 10 == 0) System.print()
}
System.print()
/... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Phix | Phix | with javascript_semantics
function three_way_partition(sequence s, integer mid)
integer i=1, j=1, n = length(s)
while j <= n do
if s[j] < mid then
{s[i],s[j]} = {s[j],s[i]}
i += 1
j += 1
elsif s[j] > mid then
{s[j],s[n]} = {s[n],s[j]}
n... |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Logo | Logo | to cuboid :l1 :l2 :l3
cs perspective ;making the room ready to use
setxyz :l1 0 0
setxyz :l1 :l2 0
setxyz 0 :l2 0
setxyz 0 0 0
setxyz :l1 0 0
setxyz :l1 0 -:l3
setxyz :l1 :l2 -:l3
setxyz :l1 :l2 0
setxyz 0 :l2 0
setxyz 0 :l2 -:l3
setxyz :l1 :l2 -:l3
end |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #Commodore_BASIC | Commodore BASIC |
10 REM DRAGON CURVE
20 REM SIN, COS IN ARRAYS FOR PI/4 MULTIPL.
30 DIM S(7),C(7)
40 QPI=ATN(1)
50 FOR I=0 TO 7
60 S(I)=SIN(I*QPI)
70 C(I)=COS(I*QPI)
80 NEXT I
90 LEVEL=15
100 INSIZE=128:REM 2^WHOLE_NUM (LOOKS BETTER)
110 X=112
120 Y=70
130 SQ=SQR(2)
140 ROTQPI=0:ITER=0:RQ=1
150 DIM R(LEVEL)
160 GRAPHIC 2,1
170 GOSUB ... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Go | Go | package main
import (
"fmt"
"image"
"image/color"
"image/png"
"math"
"os"
)
type vector [3]float64
func normalize(v *vector) {
invLen := 1 / math.Sqrt(dot(v, v))
v[0] *= invLen
v[1] *= invLen
v[2] *= invLen
}
func dot(x, y *vector) float64 {
return x[0]*y[0] + x[1]*y[... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #Go | Go | package main
import (
"golang.org/x/net/websocket"
"flag"
"fmt"
"html/template"
"io"
"math"
"net/http"
"time"
)
var (
Portnum string
Hostsite string
)
type PageSettings struct {
Host string
Port string
}
const (
Canvaswidth = 512
Canvasheight = 512
//color constants
HourColor = "#ff7373" // ... |
http://rosettacode.org/wiki/Doubly-linked_list/Traversal | Doubly-linked list/Traversal | Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
Linked list
Queue: Def... | #zkl | zkl | class Node{
fcn init(_value,_prev=Void,_next=Void)
{ var value=_value, prev=_prev, next=_next; }
fcn toString{ value.toString() }
fcn append(value){
b,c := Node(value,self,next),next;
next=b;
if(c) c.prev=b;
b
}
} |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #Picat | Picat | go =>
_ = random2(), % random seed
N = 21,
Map = new_map([1=red,2=white,3=blue]),
[Rand,Sorted] = dutch_random_sort(N,Map,Map.inverse()),
println('rand '=Rand),
println(sorted=Sorted),
nl.
% generate a random order and ensure it's not already dutch sorted
dutch_random_sort(N,Map,MapInv) = [Rand,Sorted]... |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #PicoLisp | PicoLisp | (def 'Colors
(list
(def 'RED 1)
(def 'WHITE 2)
(def 'BLUE 3) ) )
(let (L (make (do 9 (link (get Colors (rand 1 3))))) S (by val sort L))
(prin "Original balls ")
(print L)
(prinl (unless (= L S) " not sorted"))
(prin "Sorted balls ")
(print S)
(prinl " are sorted") ) |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #LSL | LSL | vector vSCALE = <2.0, 3.0, 4.0>;
default {
state_entry() {
llSetScale(vSCALE);
}
} |
http://rosettacode.org/wiki/Draw_a_cuboid | Draw a cuboid | Task
Draw a cuboid with relative dimensions of 2 × 3 × 4.
The cuboid can be represented graphically, or in ASCII art, depending on the language capabilities.
To fulfill the criteria of being a cuboid, three faces must be visible.
Either static or rotational projection is acceptable for this task.
R... | #Lua | Lua | -- needed for actual task
cube.scale = function(self, sx, sy, sz)
for i,v in ipairs(self.verts) do
v[1], v[2], v[3] = v[1]*sx, v[2]*sy, v[3]*sz
end
end
-- only needed for output
-- (to size it for screen, given a limited camera)
cube.translate = function(self, tx, ty, tz)
for i,v in ipairs(self.verts) do
... |
http://rosettacode.org/wiki/Dragon_curve | Dragon curve |
Create and display a dragon curve fractal.
(You may either display the curve directly or write it to an image file.)
Algorithms
Here are some brief notes the algorithms used and how they might suit various languages.
Recursively a right curling dragon is a right dragon followed by a left dragon, at 90-degree an... | #Common_Lisp | Common Lisp | (defpackage #:dragon
(:use #:clim-lisp #:clim)
(:export #:dragon #:dragon-part))
(in-package #:dragon)
(defun dragon-part (depth bend-direction)
(if (zerop depth)
(draw-line* *standard-output* 0 0 1 0)
(with-scaling (t (/ (sqrt 2)))
(with-rotation (t (* pi -1/4 bend-direction))
(dr... |
http://rosettacode.org/wiki/Draw_a_sphere | Draw a sphere | Task
Draw a sphere.
The sphere can be represented graphically, or in ASCII art, depending on the language capabilities.
Either static or rotational projection is acceptable for this task.
Related tasks
draw a cuboid
draw a rotating cube
write language name in 3D ASCII
draw a Deathstar
| #Haskell | Haskell | import Graphics.Rendering.OpenGL.GL
import Graphics.UI.GLUT.Objects
import Graphics.UI.GLUT
setProjection :: IO ()
setProjection = do
matrixMode $= Projection
ortho (-1) 1 (-1) 1 0 (-1)
grey1,grey9,red,white :: Color4 GLfloat
grey1 = Color4 0.1 0.1 0.1 1
grey9 = Color4 0.9 0.9 0.9 1
red = Color4 1 0 0 1... |
http://rosettacode.org/wiki/Draw_a_clock | Draw a clock | Task
Draw a clock.
More specific:
Draw a time keeping device. It can be a stopwatch, hourglass, sundial, a mouth counting "one thousand and one", anything. Only showing the seconds is required, e.g.: a watch with just a second hand will suffice. However, it must clearly change every second, and the change must cy... | #GUISS | GUISS | Start,Programs,Accessories,Analogue Clock |
http://rosettacode.org/wiki/Dutch_national_flag_problem | Dutch national flag problem |
The Dutch national flag is composed of three coloured bands in the order:
red (top)
then white, and
lastly blue (at the bottom).
The problem posed by Edsger Dijkstra is:
Given a number of red, blue and white balls in random order, arrange them in the order of the colours in the Dutch national fla... | #PowerShell | PowerShell |
$Colors = 'red', 'white','blue'
# Select 10 random colors
$RandomBalls = 1..10 | ForEach { $Colors | Get-Random }
# Ensure we aren't finished before we start. For some reason. It's in the task requirements.
While ( $RandomBalls -eq $RandomBalls | Sort { $Colors.IndexOf( $_ ) } )
{ $RandomBalls = 1..10 | For... |
Subsets and Splits
Rosetta Code COBOL Python Hard Tasks
Identifies and retrieves challenging tasks that exist in both COBOL and Python, revealing cross-language programming patterns and difficulty levels for comparative analysis.
Rosetta Code Task Comparisons
Identifies tasks common to both COBOL and Python languages that are described as having difficulty levels, revealing cross-language task similarities and providing useful comparative programming examples.
SQL Code Examples from Training Data
Retrieves raw SQL code examples for the SQL language, which is basic data retrieval without meaningful analysis or patterns.
SQL Code Examples from Training Data
Retrieves raw SQL code examples for the SQL language, which is basic filtering that shows what data looks like but doesn't provide meaningful analysis or patterns.
Select Specific Languages Codes
Retrieves specific programming language names and codes from training data, providing basic filtering but limited analytical value beyond identifying these particular languages.