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/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Phix | Phix | enum NEXT,DATA
type slnode(object x)
return (sequence(x) and length(x)=DATA and myotherudt(x[DATA]) and integer(x[NEXT])
end type
|
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #PicoLisp | PicoLisp |
declare 1 node based (p),
2 value fixed,
2 link pointer;
|
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Beads | Beads | beads 1 program simple title:'Simple windowed application' // written by CodingFiend
var g : record // global tracked mutable state
label : str
nclicks : num
========================
calc main_init // our one time initialization for the program
g.label = "There have been no clicks yet"
g.nclicks = 0
=====... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #Logo | Logo | to last :list
if empty? bf :list [output first :list]
output last bf :list
end |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #Logtalk | Logtalk |
:- object(singly_linked_list).
:- public(show/0).
show :-
traverse([1,2,3]).
traverse([]).
traverse([Head| Tail]) :-
write(Head), nl,
traverse(Tail).
:- end_object.
|
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #jq | jq | def new($item; $next):
if $next | (.==null or is_singly_linked_list)
then {$item, $next}
else "new(_;_) called with invalid SLL: \($next)" | error
end;
# A constructor:
def new($x): new($x; null);
def insert($x):
.next |= new($x; .); |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Julia | Julia | function Base.insert!(ll::LinkedList{T}, index::Integer, item::T) where T
if index == 1
if isempty(ll)
return push!(ll, item)
else
ll.head = Node{T}(item, ll.head)
end
else
nd = ll.head
while index > 2
if nd.next isa EmptyNode
... |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Elena | Elena | import extensions;
public program()
{
int sleep := console.readLine().toInt();
console.printLine("Sleeping...");
system'threading'threadControl.sleep(sleep);
console.printLine("Awake!")
} |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Elixir | Elixir | sleep = fn seconds ->
IO.puts "Sleeping..."
:timer.sleep(1000 * seconds) # in milliseconds
IO.puts "Awake!"
end
sec = if System.argv==[], do: 1, else: hd(System.argv) |> String.to_integer
sleep.(sec) |
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort | Sorting algorithms/Bubble sort |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #VBA | VBA | Private Function bubble_sort(s As Variant) As Variant
Dim tmp As Variant
Dim changed As Boolean
For j = UBound(s) To 1 Step -1
changed = False
For i = 1 To j - 1
If s(i) > s(i + 1) Then
tmp = s(i)
s(i) = s(i + 1)
s(i + 1) = tmp
... |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #PL.2FI | PL/I |
declare 1 node based (p),
2 value fixed,
2 link pointer;
|
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Pop11 | Pop11 | ;;; Use shorthand syntax to create list.
lvars l1 = [1 2 three 'four'];
;;; Allocate a single list node, with value field 1 and the link field
;;; pointing to empty list
lvars l2 = cons(1, []);
;;; print first element of l1
front(l1) =>
;;; print the rest of l1
back(l1) =>
;;; Use index notation to access third element... |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #PureBasic | PureBasic | Structure MyData
*next.MyData
Value.i
EndStructure |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #C | C | #include <stdio.h>
#include <gtk/gtk.h>
const gchar *clickme = "Click Me";
guint counter = 0;
#define MAXLEN 64
void clickedme(GtkButton *o, gpointer d)
{
GtkLabel *l = GTK_LABEL(d);
char nt[MAXLEN];
counter++;
snprintf(nt, MAXLEN, "You clicked me %d times", counter);
gtk_label_set_text(l, nt)... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | Print /@ {"rosettacode", "kitten", "sitting", "rosettacode", "raisethysword"} |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #MATLAB_.2F_Octave | MATLAB / Octave | list = 1:10;
for k=1:length(list)
printf('%i\n',list(k))
end; |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Kotlin | Kotlin | // version 1.1.2
class Node<T: Number>(var data: T, var next: Node<T>? = null) {
override fun toString(): String {
val sb = StringBuilder(this.data.toString())
var node = this.next
while (node != null) {
sb.append(" -> ", node.data.toString())
node = node.next
... |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Emacs_Lisp | Emacs Lisp | (let ((seconds (read-number "Time in seconds: ")))
(message "Sleeping ...")
(sleep-for seconds)
(message "Awake!")) |
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort | Sorting algorithms/Bubble sort |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #VBScript | VBScript |
sub decr( byref n )
n = n - 1
end sub
sub incr( byref n )
n = n + 1
end sub
sub swap( byref a, byref b)
dim tmp
tmp = a
a = b
b = tmp
end sub
function bubbleSort( a )
dim changed
dim itemCount
itemCount = ubound(a)
do
changed = false
decr itemCount
for i = 0 to itemCount
if a(i) > a(i+1) the... |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Python | Python | class LinkedList(object):
"""USELESS academic/classroom example of a linked list implemented in Python.
Don't ever consider using something this crude! Use the built-in list() type!
"""
class Node(object):
def __init__(self, item):
self.value = item
self.next = None
def __init__(self, item... |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Racket | Racket |
#lang racket
(mcons 1 (mcons 2 (mcons 3 '()))) ; a mutable list
|
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #C.23 | C# | using System.Windows.Forms;
class RosettaForm : Form
{
RosettaForm()
{
var clickCount = 0;
var label = new Label();
label.Text = "There have been no clicks yet.";
label.Dock = DockStyle.Top;
Controls.Add(label);
var button = new Button();
button.Text... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #MiniScript | MiniScript | myList = [2, 4, 6, 8]
for i in myList
print i
end for |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #Nanoquery | Nanoquery | first = new(link)
//
for (iter = first) (iter != null) (iter = iter.next)
println iter.data
end |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Logo | Logo | to insert :after :list :value
localmake "tail member :after :list
if not empty? :tail [.setbf :tail fput :value bf :tail]
output :list
end
show insert 5 [3 5 1 8] 2 |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | Append[{a, b}, c]
->{a, b, c} |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Erlang | Erlang | main() ->
io:format("Sleeping...~n"),
timer:sleep(1000), %% in milliseconds
io:format("Awake!~n"). |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #ERRE | ERRE |
..............
INPUT("Enter the time to sleep in seconds: ";sleep)
PRINT("Sleeping...")
PAUSE(sleep)
PRINT("Awake!")
..............
|
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort | Sorting algorithms/Bubble sort |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Visual_Basic_.NET | Visual Basic .NET | Do Until NoMoreSwaps = True
NoMoreSwaps = True
For Counter = 1 To (NumberOfItems - 1)
If List(Counter) > List(Counter + 1) Then
NoMoreSwaps = False
Temp = List(Counter)
List(Counter) = List(Counter + 1)
List(Counter + 1) = Temp
End If
... |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Raku | Raku | my $elem = 42 => $nextelem; |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #REXX | REXX | /*REXX program demonstrates how to create and show a single-linked list.*/
@.=0 /*define a null linked list. */
call set@ 3 /*linked list: 12 Proth Primes. */
call set@ 5
call set@ 13
call set@ 17
call set@ 41
call set@ 97
call set@ 113
call set@ 193
cal... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #C.2B.2B | C++ | #ifndef CLICKCOUNTER_H
#define CLICKCOUNTER_H
#include <QWidget>
class QLabel ;
class QPushButton ;
class QVBoxLayout ;
class Counter : public QWidget {
Q_OBJECT
public :
Counter( QWidget * parent = 0 ) ;
private :
int number ;
QLabel *countLabel ;
QPushButton *clicker ;
QVBoxLayout *myLayout ;
p... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #NewLISP | NewLISP | (dolist (x '(a b c d e))
(println x)) |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #Nim | Nim | type Node[T] = ref object
next: Node[T]
data: T
proc newNode[T](data: T): Node[T] =
Node[T](data: data)
var a = newNode 12
var b = newNode 13
var c = newNode 14
proc insertAppend(a, n: var Node) =
n.next = a.next
a.next = n
a.insertAppend(b)
b.insertAppend(c)
iterator items(a: Node) =
var x = a
... |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Modula-3 | Modula-3 | MODULE SinglyLinkedList EXPORTS Main;
TYPE
Link = REF LinkRcd;
LinkRcd = RECORD
Next: Link;
Data: INTEGER
END;
PROCEDURE InsertAppend(anchor, next: Link) =
BEGIN
IF anchor # NIL AND next # NIL THEN
next.Next := anchor.Next;
anchor.Next := next
END
END InsertAppend;
VAR
a:... |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Nim | Nim | type Node[T] = ref object
next: Node[T]
data: T
proc newNode[T](data: T): Node[T] =
Node[T](data: data)
var a = newNode 12
var b = newNode 13
var c = newNode 14
proc insertAppend(a, n: var Node) =
n.next = a.next
a.next = n
a.insertAppend(b)
b.insertAppend(c) |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #F.23 | F# | open System
open System.Threading
[<EntryPoint>]
let main args =
let sleep = Convert.ToInt32(Console.ReadLine())
Console.WriteLine("Sleeping...")
Thread.Sleep(sleep); //milliseconds
Console.WriteLine("Awake!")
0 |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Factor | Factor | USING: calendar io math.parser threads ;
: read-sleep ( -- )
readln string>number seconds
"Sleeping..." print
sleep
"Awake!" print ; |
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort | Sorting algorithms/Bubble sort |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Vlang | Vlang | fn bubble(mut arr []int) {
println('Input: ${arr.str()}')
mut count := arr.len
for {
if count <= 1 {
break
}
mut has_changed := false
count--
for i := 0; i < count; i++ {
... |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Ruby | Ruby | class ListNode
attr_accessor :value, :succ
def initialize(value, succ=nil)
self.value = value
self.succ = succ
end
def each(&b)
yield self
succ.each(&b) if succ
end
include Enumerable
def self.from_array(ary)
head = self.new(ary[0], nil)
prev = head
ary[1..-1].each do |... |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Run_BASIC | Run BASIC | data = 10
link = 10
dim node{data,link} |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Clojure | Clojure | (ns counter-window
(:import (javax.swing JFrame JLabel JButton)))
(defmacro on-action [component event & body]
`(. ~component addActionListener
(proxy [java.awt.event.ActionListener] []
(actionPerformed [~event] ~@body))))
(defn counter-app []
(let [counter (atom 0)
label (JLabel. "There... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #Objeck | Objeck |
for(node := head; node <> Nil; node := node->GetNext();) {
node->GetValue()->PrintLine();
};
|
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #Objective-C | Objective-C | RCListElement *current;
for(current=first_of_the_list; current != nil; current = [current next] )
{
// to get the "datum":
// id dat_obj = [current datum];
} |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #OCaml | OCaml | let rec insert_after a b = function
c :: cs when a = c -> a :: b :: cs
| c :: cs -> c :: insert_after a b cs
| [] -> raise Not_found |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Oforth | Oforth | Collection Class new: LinkedList(data, mutable next)
LinkedList method: initialize := next := data ;
LinkedList method: data @data ;
LinkedList method: next @next ;
LinkedList method: add(e) e @next LinkedList new := next ;
LinkedList method: forEachNext
dup ifNull: [ drop self ]
dup 1 ifEq: [ drop fals... |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Fantom | Fantom |
using concurrent
class Main
{
public static Void main ()
{
echo ("Enter a time to sleep: ")
input := Env.cur.in.readLine
try
{
time := Duration.fromStr (input)
echo ("sleeping ...")
Actor.sleep (time)
echo ("awake!")
}
catch
{
echo ("Invalid time entered... |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #FBSL | FBSL | #APPTYPE CONSOLE
DIM %msec
PRINT "Milliseconds to sleep: ";
%msec = FILEGETS(stdin, 10)
PRINT "Sleeping..."
SLEEP(%msec)
PRINT "Awake!"
PAUSE
|
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort | Sorting algorithms/Bubble sort |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Wren | Wren | var bubbleSort = Fn.new { |a|
var n = a.count
if (n < 2) return
while (true) {
var swapped = false
for (i in 1..n-1) {
if (a[i-1] > a[i]) {
var t = a[i-1]
a[i-1] = a[i]
a[i] = t
swapped = true
}
}... |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Rust | Rust | struct Node<T> {
elem: T,
next: Option<Box<Node<T>>>,
} |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Scala | Scala |
sealed trait List[+A]
case class Cons[+A](head: A, tail: List[A]) extends List[A]
case object Nil extends List[Nothing]
object List {
def apply[A](as: A*): List[A] =
if (as.isEmpty) Nil else Cons(as.head, apply(as.tail: _*))
}
|
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Common_Lisp | Common Lisp | (defpackage #:rcswa
(:use #:clim #:clim-lisp))
(in-package #:rcswa) |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #OCaml | OCaml | # let li = ["big"; "fjords"; "vex"; "quick"; "waltz"; "nymph"] in
List.iter print_endline li ;;
big
fjords
vex
quick
waltz
nymph
- : unit = () |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #Oforth | Oforth | : testLink LinkedList new($A, null) dup add($B) dup add($C) ;
testLink apply(#println) |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #ooRexx | ooRexx |
list = .linkedlist~new
index = list~insert("abc") -- insert a first item, keeping the index
list~insert("def") -- adds to the end
list~insert("123", .nil) -- adds to the begining
list~insert("456", index) -- inserts between "abc" and "def"
list~remove(index) -- removes "abc"
|
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Pascal | Pascal | type
pCharNode = ^CharNode;
CharNode = record
data: char;
next: pCharNode;
end;
(* This procedure inserts a node (newnode) directly after another node which is assumed to already be in a list.
It does not allocate a new node, but takes an already allocated node, thus a... |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Forth | Forth | : sleep ( ms -- )
." Sleeping..."
ms
." awake." cr ; |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Fortran | Fortran | program test_sleep
implicit none
integer :: iostat
integer :: seconds
character (32) :: argument
if (iargc () == 1) then
call getarg (1, argument)
read (argument, *, iostat = iostat) seconds
if (iostat == 0) then
write (*, '(a)') 'Sleeping...'
call sleep (seconds)
write (*, '... |
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort | Sorting algorithms/Bubble sort |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #X86_Assembly | X86 Assembly | .model tiny
.code
.486
org 100h
start: mov si, offset array
mov ax, 40 ;length of array (not including $)
call bsort
mov dx, si ;point to array
mov ah, 09h ;display it as a string
int 21h
... |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Scheme | Scheme | (cons value next) |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Sidef | Sidef | var node = Hash.new(
data => 'say what',
next => foo_node,
);
node{:next} = bar_node; # mutable |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #SSEM | SSEM | 01000000000000000000000000000000 26. 2
01111000000000000000000000000000 27. 30
10000000000000000000000000000000 28. 1
01011000000000000000000000000000 29. 26
11000000000000000000000000000000 30. 3
00000000000000000000000000000000 31. 0 |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #D | D | module winapp ;
import dfl.all ;
import std.string ;
class MainForm: Form {
Label label ;
Button button ;
this() {
width = 240 ;
with(label = new Label) {
text = "There have been no clicks yet" ;
dock = DockStyle.TOP ;
parent = this ;
}
with(button = new Button) {
do... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #ooRexx | ooRexx | list=.list~of('A','B','X')
say "Manual list traversal"
index=list~first
loop while index \== .nil
say list~at(index)
index = list~next(index)
end
say
say "Do ... Over traversal"
do value over list
say value
end |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Perl | Perl | my @l = ($A, $B);
push @l, $C, splice @l, 1; |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Phix | Phix | with javascript_semantics
enum NEXT,DATA
constant empty_sll = {{1}}
sequence sll = deep_copy(empty_sll)
procedure insert_after(object data, integer pos=length(sll))
sll = append(sll,{sll[pos][NEXT],data})
sll[pos][NEXT] = length(sll)
end procedure
insert_after("ONE")
insert_after("TWO")
insert_after("THREE"... |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #FreeBASIC | FreeBASIC | ' FB 1.05.0 Win64
Dim ms As UInteger
Input "Enter number of milliseconds to sleep" ; ms
Print "Sleeping..."
Sleep ms, 1 '' the "1" means Sleep can't be interrupted with a keystroke
Print "Awake!"
End |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Frink | Frink |
do
t = eval[input["Enter amount of time to sleep: ", "1 second"]]
while ! (t conforms time)
println["Sleeping..."]
sleep[t]
println["Awake!"]
|
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort | Sorting algorithms/Bubble sort |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Xojo | Xojo | Dim temp, count As Integer
Dim isDirty As Boolean
count = Ubound(list) // count the array size
// loop through until we don't move any numbers... this means we are sorted
Do
isDirty = False // we haven't touched anything yet
For i As Integer = 1 To count - 1 // loop through all the numbers
If list(i) > list(i... |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Stata | Stata | struct item {
transmorphic scalar value
pointer(struct item scalar) scalar next
}
struct list {
pointer(struct item scalar) scalar head, tail
} |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Swift | Swift | class Node<T>{
var data:T?=nil
var next:Node?=nil
init(input:T){
data=input
next=nil
}
}
|
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Tcl | Tcl | oo::class create List {
variable content next
constructor {value {list ""}} {
set content $value
set next $list
}
method value args {
set content {*}$args
}
method attach {list} {
set next $list
}
method detach {} {
set next ""
}
method nex... |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Delphi | Delphi | -- begin file --
Program SingleWinApp ;
// This is the equivalent of the C #include
Uses Forms, Windows, Messages, Classes, Graphics, Controls, StdCtrls ;
type
// The only reason for this declaration is to allow the connection of the
// on click method to the forms button object. This cl... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #Pascal | Pascal | <@ LETCNSLSTLIT>public holidays|開國紀念日^和平紀念日^婦女節、兒童節合併假期^清明節^國慶日^春節^端午節^中秋節^農曆除夕</@>
<@ OMT>From First to Last</@>
<@ ITEFORSZELSTLIT>public holidays|
<@ SAYLST>...</@><@ ACTMOVFWDLST>...</@>
</@>
<@ OMT>From Last to First (pointer is still at end of list)</@>
<@ ITEFORSZELSTLIT>public holidays|
<@ SAYLST>...</@><@ ACTM... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #Peloton | Peloton | <@ LETCNSLSTLIT>public holidays|開國紀念日^和平紀念日^婦女節、兒童節合併假期^清明節^國慶日^春節^端午節^中秋節^農曆除夕</@>
<@ OMT>From First to Last</@>
<@ ITEFORSZELSTLIT>public holidays|
<@ SAYLST>...</@><@ ACTMOVFWDLST>...</@>
</@>
<@ OMT>From Last to First (pointer is still at end of list)</@>
<@ ITEFORSZELSTLIT>public holidays|
<@ SAYLST>...</@><@ ACTM... |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #PicoLisp | PicoLisp | (de insertAfter (Item Lst New)
(when (member Item Lst)
(con @ (cons New (cdr @))) )
Lst ) |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #PL.2FI | PL/I |
/* Let H be a pointer to a node in a one-way-linked list. */
/* Insert an element, whose value is given by variable V, following that node. */
allocate node set (Q);
node.p = H; /* The new node now points at the list where we want to insert it. */
node.value = V;
H->p = Q; /* Break the list at H, and point it at ... |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Pop11 | Pop11 | define insert_into_list(anchor, x);
cons(x, back(anchor)) -> back(anchor);
enddefine;
;;; Build inital list
lvars l1 = cons("a", []);
insert_into_list(l1, "b");
;;; insert c
insert_into_list(l1, "c"); |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Go | Go | package main
import "time"
import "fmt"
func main() {
fmt.Print("Enter number of seconds to sleep: ")
var sec float64
fmt.Scanf("%f", &sec)
fmt.Print("Sleeping…")
time.Sleep(time.Duration(sec * float64(time.Second)))
fmt.Println("\nAwake!")
} |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Groovy | Groovy | def sleepTest = {
println("Sleeping...")
sleep(it)
println("Awake!")
} |
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort | Sorting algorithms/Bubble sort |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #XPL0 | XPL0 | include c:\cxpl\codes; \intrinsic 'code' declarations
string 0; \use zero-terminated strings
proc BSort(A, N); \Bubble sort array in ascending order
char A; \address of array
int N; \number of items in array (size)
int I... |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Wren | Wren | import "/llist" for Node
var n1 = Node.new(1)
var n2 = Node.new(2)
n1.next = n2
System.print(["node 1", "data = %(n1.data)", "next = %(n1.next)"])
System.print(["node 2", "data = %(n2.data)", "next = %(n2.next)"]) |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #X86_Assembly | X86 Assembly |
; x86_64 Linux NASM
; Linked_List_Definition.asm
%ifndef LinkedListDefinition
%define LinkedListDefinition
struc link
value: resd 1
next: resq 1
linkSize:
endstruc
%endif
|
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #E | E | when (currentVat.morphInto("awt")) -> {
var clicks := 0
def w := <swing:makeJFrame>("Rosetta Code 'Simple Windowed Application'")
w.setContentPane(JPanel`
${def l := <swing:makeJLabel>("There have been no clicks yet.")} $\
${def b := <swing:makeJButton>("Click Me")}
`)
b.addActio... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #Perl | Perl | package SSL_Node;
use strict;
use Class::Tiny qw( val next );
sub BUILD {
my $self = shift;
exists($self->{val}) or die "Must supply 'val'";
if (exists $self->{next}) {
ref($self->{next}) eq 'SSL_Node'
or die "If supplied, 'next' must be an SSL_Node";
}
return;
}
package main... |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #PureBasic | PureBasic | Procedure insertAfter(Value, *node.MyData = #Null)
Protected *newNode.MyData = AllocateMemory(SizeOf(MyData))
If *newNode
If *node
*newNode\next = *node\next
*node\next = *newNode
EndIf
*newNode\Value = Value
EndIf
ProcedureReturn *newNode ;return pointer to newnode
EndProcedure
De... |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Python | Python | def chain_insert(lst, at, item):
while lst is not None:
if lst[0] == at:
lst[1] = [item, lst[1]]
return
else:
lst = lst[1]
raise ValueError(str(at) + " not found")
chain = ['A', ['B', None]]
chain_insert(chain, 'A', 'C')
print chain |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Haskell | Haskell | import Control.Concurrent
main = do seconds <- readLn
putStrLn "Sleeping..."
threadDelay $ round $ seconds * 1000000
putStrLn "Awake!" |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #HicEst | HicEst | DLG(NameEdit = milliseconds, Button = "Go to sleep")
WRITE(StatusBar) "Sleeping ... "
SYSTEM(WAIT = milliseconds)
WRITE(Messagebox) "Awake!" |
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort | Sorting algorithms/Bubble sort |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Yabasic | Yabasic | // Animated sort.
// Original idea by William Tang, obtained from MicroHobby 25 Years (https://microhobby.speccy.cz/zxsf/MH-25Years.pdf)
clear screen
n=15 : m=18 : y=9 : t$=chr$(17)+chr$(205)+chr$(205)
dim p(n), p$(n)
for x=1 TO n
p(x)=ran(15)+1
p$(x)=str$(p(x),"##.######")
print at(0,x) p$(x)
next x
... |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #XPL0 | XPL0 | def \Node\ Link, Data; \linked list element definition
int Node, List, N;
def IntSize = 4; \number of bytes in an integer
[List:= 0; \List is initially empty
for N:= 1 to 10 do \build linked list, starting at the end
[Node:= R... |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #Zig | Zig | const std = @import("std");
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const allocator = arena.allocator();
pub fn LinkedList(comptime Value: type) type {
return struct {
const This = @This();
const Node = struct {
value: Value,
next: ?*Node,
... |
http://rosettacode.org/wiki/Singly-linked_list/Element_definition | Singly-linked list/Element definition | singly-linked list
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: Definition, Usage
Set
Singly-linked list: Element definition, Element insertion, Lis... | #zkl | zkl | List(1,"two",3.14); L(1,"two",3.14);
ROList(fcn{"foobar"}); T('+); |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #EchoLisp | EchoLisp |
(define (ui-add-button text) ;; helper
(define b (ui-create-element "button" '((type "button"))))
(ui-set-html b text)
(ui-add b))
(define (panel )
(ui-clear)
(define *clicks* 0)
(define text (ui-create-element "span" '((style "font-weight:bold"))))
(ui-add text)
(ui-set-html text "N... |
http://rosettacode.org/wiki/Singly-linked_list/Traversal | Singly-linked list/Traversal | Traverse from the beginning of a singly-linked list to the end.
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: Definition, Usage
Set
Singly-linked ... | #Phix | Phix | with javascript_semantics
enum NEXT,DATA
constant empty_sll = {{1}}
sequence sll = deep_copy(empty_sll)
procedure insert_after(object data, integer pos=length(sll))
sll = append(sll,{sll[pos][NEXT],data})
sll[pos][NEXT] = length(sll)
end procedure
insert_after("ONE")
insert_after("TWO")
insert_after("THREE"... |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Racket | Racket |
#lang racket
;; insert b after a in a mutable list (assumes that a is in the input list)
(define (insert-after! list a b)
(if (equal? (mcar list) a)
(set-mcdr! list (mcons b (mcdr list)))
(insert-after! (mcdr list) a b)))
(define l (mcons 1 (mcons 2 (mcons 3 '()))))
(insert-after! l 2 2.5)
l ; -> (mcons... |
http://rosettacode.org/wiki/Singly-linked_list/Element_insertion | Singly-linked list/Element insertion | Singly-Linked List (element)
singly-linked list
Using this method, insert an element C into a list comprised of elements A->B, following element A.
See also
Array
Associative array: Creation, Iteration
Collections
Compound data type
Doubly-linked list: Definition, Element definition, Element insertion, List Trav... | #Raku | Raku | method insert ($value) {
$.next = Cell.new(:$value, :$.next)
} |
http://rosettacode.org/wiki/Sleep | Sleep | Task
Write a program that does the following in this order:
Input an amount of time to sleep in whatever units are most natural for your language (milliseconds, seconds, ticks, etc.). This unit should be noted in comments or in a description.
Print "Sleeping..."
Sleep the main thread for the given amount of time.
... | #Icon_and_Unicon | Icon and Unicon | procedure main()
repeat {
writes("Enter number of seconds to sleep :")
s := reads()
if s = ( 0 < integer(s)) then break
}
write("\nSleeping for ",s," seconds.")
delay(1000 * s)
write("Awake!")
end |
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort | Sorting algorithms/Bubble sort |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Yorick | Yorick | func bubblesort(&items) {
itemCount = numberof(items);
do {
hasChanged = 0;
itemCount--;
for(index = 1; index <= itemCount; index++) {
if(items(index) > items(index+1)) {
items([index,index+1]) = items([index+1,index]);
hasChanged = 1;
}
}
} while(hasChanged);
} |
http://rosettacode.org/wiki/Simple_windowed_application | Simple windowed application | Task
Create a window that has:
a label that says "There have been no clicks yet"
a button that says "click me"
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
| #Elena | Elena | import forms;
import extensions;
public class MainWindow : SDIDialog
{
Label lblClicks;
Button btmClickMe;
//Store how much clicks the user doed
int clicksCount;
constructor new()
<= new()
{
lblClicks := Label.new();
btmClickMe := Button.new();
cli... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.