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_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...
#Clojure
Clojure
(defn insert-after [new old ls] (cond (empty? ls) ls (= (first ls) old) (cons old (cons new (rest ls))) :else (cons (first ls) (insert-after new old (rest ls)))))
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. ...
#BASIC
BASIC
INPUT sec 'the SLEEP command takes seconds PRINT "Sleeping..." SLEEP sec PRINT "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. ...
#Batch_File
Batch File
@echo off set /p Seconds=Enter the number of seconds to sleep: set /a Seconds+=1 echo Sleeping ... ping -n %Seconds% localhost >nul 2>&1 echo 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 ...
#Symsyn
Symsyn
    x : 23 : 15 : 99 : 146 : 3 : 66 : 71 : 5 : 23 : 73 : 19   bubble_sort param index size   + index size limit lp changes - limit index i if i < limit + 1 i ip1 if base.i > base.ip1 swap base.i base.ip1 + changes endif + i goif endif if changes > 0 go lp endif retu...
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...
#Go
Go
type Ele struct { Data interface{} Next *Ele }   func (e *Ele) Append(data interface{}) *Ele { if e.Next == nil { e.Next = &Ele{data, nil} } else { tmp := &Ele{data, e.Next} e.Next = tmp } return e.Next }   func (e *Ele) String() string { return fmt.Sprintf("Ele: %v",...
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...
#Groovy
Groovy
class ListNode { Object payload ListNode next String toString() { "${payload} -> ${next}" } }
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 ...
#EchoLisp
EchoLisp
  (define friends '( albert ludwig elvis 🌀))   (for-each write friends)→ albert ludwig elvis 🌀   ; for loop (for ((friend friends)) (write friend)) → albert ludwig elvis 🌀   ; map a function (map string-upcase friends) → ("ALBERT" "LUDWIG" "ELVIS" "🌀") (map string-randcase friends) → ("ALBerT" "LudWIG" "elVis" "�...
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...
#Common_Lisp
Common Lisp
(defun insert-after (new-element old-element list &key (test 'eql)) "Return a list like list, but with new-element appearing after the first occurence of old-element. If old-element does not appear in list, then a list returning just new-element is returned." (if (endp list) (list new-element) (do ((head (list ...
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. ...
#BBC_BASIC
BBC BASIC
INPUT "Enter the time to sleep in centiseconds: " sleep% PRINT "Sleeping..." WAIT sleep% PRINT "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. ...
#C
C
#include <stdio.h> #include <unistd.h>   int main() { unsigned int seconds; scanf("%u", &seconds); printf("Sleeping...\n"); sleep(seconds); printf("Awake!\n"); return 0; }
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 ...
#Tailspin
Tailspin
  templates bubblesort templates bubble @: 1; 1..$-1 -> # $@ ! when <?($@bubblesort($+1) <..~$@bubblesort($)>)> do @: $; def temp: $@bubblesort($@); @bubblesort($@): $@bubblesort($@+1); @bubblesort($@+1): $temp; end bubble   @: $; $::length -> # $@ !   when <2..> 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...
#Haskell
Haskell
data List a = Nil | Cons a (List a)
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...
#Icon_and_Unicon
Icon and Unicon
  record Node (value, successor)  
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 ...
#Ela
Ela
traverse [] = [] traverse (x::xs) = x :: traverse xs
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 ...
#Elena
Elena
  while(nil != current){ console printLine(current.Item); current := current.Next }
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...
#D
D
struct SLinkedNode(T) { T data; typeof(this)* next; }   void insertAfter(T)(SLinkedNode!T* listNode, SLinkedNode!T* newNode) { newNode.next = listNode.next; listNode.next = newNode; }   void main() { alias N = SLinkedNode!char;   auto lh = new N('A', new N('B')); auto c = new N('C');   /...
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...
#Delphi
Delphi
// Using the same type defs from the one way list example.   Type   // The pointer to the list structure pOneWayList = ^OneWayList;   // The list structure OneWayList = record pData : pointer ; Next : pOneWayList ; end;   // I will illustrate a simple function t...
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. ...
#C.23
C#
using System; using System.Threading;   class Program { static void Main(string[] args) { int sleep = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Sleeping..."); Thread.Sleep(sleep); //milliseconds Console.WriteLine("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 ...
#Tcl
Tcl
package require Tcl 8.5 package require struct::list   proc bubblesort {A} { set len [llength $A] set swapped true while {$swapped} { set swapped false for {set i 0} {$i < $len - 1} {incr i} { set j [expr {$i + 1}] if {[lindex $A $i] > [lindex $A $j]} { ...
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...
#J
J
list=: 0 2$0 list
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...
#Java
Java
class Link { Link next; int data; }
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.
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program simpleWin64.s link with X11 library */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "...
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 ...
#Erlang
Erlang
1> lists:map( fun erlang:is_integer/1, [1,2,3,a,b,c] ). [true,true,true,false,false,false] 4> lists:foldl( fun erlang:'+'/2, 0, [1,2,3] ). 6
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 ...
#Factor
Factor
: list-each ( linked-list quot: ( data -- ) -- ) [ [ data>> ] dip call ] [ [ next>> ] dip over [ list-each ] [ 2drop ] if ] 2bi ; inline recursive   SYMBOLS: A B C ;   A <linked-list> [ C <linked-list> list-insert ] keep [ B <linked-list> list-insert ] keep   [ . ] list-each
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...
#E
E
def insertAfter(head :LinkedList ? (!head.null()), new :LinkedList ? (new.next().null())) { new.setNext(head.next()) head.setNext(new) }   def a := makeLink(1, empty) def b := makeLink(2, empty) def c := makeLink(3, empty)   insertAfter(a, b) insertAfter(a, c)   var x := a while (!x.null()) { ...
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...
#EchoLisp
EchoLisp
  (define (insert-after lst target item) (when (null? lst) (error "cannot insert in" null)) (let [(sub-list (member target lst))] (if sub-list (set-cdr! sub-list (cons item (cdr sub-list))) ; make chirurgy if found (nconc lst item)))) ; else append item   (define L '(a b)) (insert-after L '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. ...
#C.2B.2B
C++
#include <iostream> #include <thread> #include <chrono> int main() { unsigned long microseconds; std::cin >> microseconds; std::cout << "Sleeping..." << std::endl; std::this_thread::sleep_for(std::chrono::microseconds(microseconds)); std::cout << "Awake!\n"; }  
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 ...
#TI-83_BASIC
TI-83 BASIC
:L1→L2 :1+dim(L2)→N :For(D,1,dim(L2)) :N-1→N :0→I :For(C,1,dim(L2)-2) :For(A,dim(L2)-N+1,dim(L2)-1) :If L2(A)>L2(A+1) :Then :1→I :L2(A)→B :L2(A+1)→L2(A) :B→L2(A+1) :End :End :End :If I=0 :Goto C :End :Lbl C :If L2(1)>L2(2) :Then :L2(1)→B :L2(2)→L2(1) :B→L2(2) :End :DelVar A :DelVar B :DelVar C :DelVar D :DelVar N :DelV...
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...
#JavaScript
JavaScript
function LinkedList(value, next) { this._value = value; this._next = next; } LinkedList.prototype.value = function() { if (arguments.length == 1) this._value = arguments[0]; else return this._value; } LinkedList.prototype.next = function() { if (arguments.length == 1) this....
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.
#Ada
Ada
with Gdk.Event; use Gdk.Event; with Gtk.Button; use Gtk.Button; with Gtk.Label; use Gtk.Label; with Gtk.Window; use Gtk.Window; with Gtk.Widget; use Gtk.Widget; with Gtk.Table; use Gtk.Table;   with Gtk.Handlers; with Gtk.Main;   procedure Simple_Windowed_Application is Window : Gtk_Window; Grid  : Gtk_...
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 ...
#Fantom
Fantom
// traverse the linked list Node? current := a while (current != null) { echo (current.value) current = current.successor }
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 ...
#Forth
Forth
: last ( list -- end ) begin dup @ while @ repeat ;
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...
#Elena
Elena
singleton linkHelper { insertAfter(Link prev, IntNumber i) { prev.Next := new Link(i, prev.Next) } }
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...
#Erlang
Erlang
  -module( singly_linked_list ).   -export( [append/2, foreach/2, free/1, insert/3, new/1, task/0] ).   append( New, Start ) -> Start ! {append, New}.   foreach( Fun, Start ) -> Start ! {foreach, Fun}.   free( Element ) -> Element ! {free}.   insert( New, After, Start ) -> Start ! {insert, New, After}.   new( Data ) ->...
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. ...
#Cach.C3.A9_ObjectScript
Caché ObjectScript
  SLEEP  ; the HANG command can use fractional seconds; the Awake line will be slightly off due to processing time read "How long to sleep in seconds?: ",sleep write !,"Sleeping... time is "_$ztime($piece($ztimestamp,",",2,2),1,2) hang +sleep  ; use + to cast numeric, if non-numeric will hang 0 wri...
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. ...
#Clojure
Clojure
(defn sleep [ms] ; time in milliseconds (println "Sleeping...") (Thread/sleep ms) (println "Awake!")) ; call it (sleep 1000)
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 ...
#Toka
Toka
#! A simple Bubble Sort function value| array count changed | [ ( address count -- ) to count to array count 0 [ count 0 [ i array array.get i 1 + array array.get 2dup > [ i array array.put i 1 + array array.put ] [ 2drop ] ifTrueFalse ] countedLoop count 1 - to count ] countedLoop ] is...
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...
#jq
jq
{"item": $item, "next": $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...
#Julia
Julia
abstract type AbstractNode{T} end   struct EmptyNode{T} <: AbstractNode{T} end mutable struct Node{T} <: AbstractNode{T} data::T next::AbstractNode{T} end Node{T}(x) where T = Node{T}(x::T, EmptyNode{T}())   mutable struct LinkedList{T} head::AbstractNode{T} end LinkedList{T}() where T = LinkedList{T}(Empty...
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.
#APL
APL
∇ WindowedApplication   ⍝ define a form with a label and a button 'Frm'⎕WC'Form' 'Clicks' (40 35) (10 15) 'Lbl'Frm.⎕WC'Label' 'There have been no clicks yet.' (10 10) 'Btn'Frm.⎕WC'Button' 'Click Me' (35 35) (25 25) ('Event' 'Select' 'Click')   ⍝ callback function Frm.Clicks←0 Frm.Click←{ Clicks+←1 p0←(1+Clicks...
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 ...
#Fortran
Fortran
subroutine traversal(list,proc) type(node), target :: list type(node), pointer :: current interface subroutine proc(node) real, intent(in) :: node end subroutine proc end interface current => list do while ( associated(current) ) call proc(current%data) current =>...
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 ...
#FreeBASIC
FreeBASIC
#define NULL 0   function alloc_ll_int( n as integer ) as ll_int ptr dim as ll_int ptr ret = allocate(sizeof(ll_int)) ret->n = n ret->nxt = NULL return ret end function   sub traverse_ll_int( head as ll_int ptr ) dim as ll_int ptr curr = head while curr <> NULL print curr->n curr...
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...
#Factor
Factor
: list-append ( previous new -- ) [ swap next>> >>next drop ] [ >>next drop ] 2bi ;   SYMBOLS: A B C ;   A <linked-list> [ C <linked-list> list-append ] keep [ B <linked-list> list-append ] keep .
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...
#Fantom
Fantom
  class Node { const Int value Node? successor // can be null, for end of series   new make (Int value, Node? successor := null) { this.value = value this.successor = successor }   // insert method for this problem public Void insert (Node newNode) { newNode.successor = this.successor th...
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. ...
#COBOL
COBOL
IDENTIFICATION DIVISION. PROGRAM-ID. Sleep-In-Seconds.   DATA DIVISION. WORKING-STORAGE SECTION. 01 Seconds-To-Sleep USAGE COMP-2.   PROCEDURE DIVISION. ACCEPT Seconds-To-Sleep   DISPLAY "Sleeping..."   CALL "C$SLEEP" USING BY CONTENT 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 ...
#TorqueScript
TorqueScript
//Note that we're assuming that the list of numbers is separated by tabs. function bubbleSort(%list) { %ct = getFieldCount(%list); for(%i = 0; %i < %ct; %i++) { for(%k = 0; %k < (%ct - %i - 1); %k++) { if(getField(%list, %k) > getField(%list, %k+1)) { %tmp = getField(%list, %k); %list = setField(%l...
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...
#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/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...
#Logo
Logo
fput item list ; add item to the head of a list   first list  ; get the data butfirst list ; get the remainder bf list  ; contraction for "butfirst"
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.
#AppleScript
AppleScript
  set counter to 0   set dialogReply to display dialog ¬ "There have been no clicks yet" buttons {"Click Me", "Quit"} ¬ with title "Simple Window Application" set theAnswer to button returned of the result if theAnswer is "Quit" then quit   repeat set counter to counter + 1 set dialogReply to display dialog counter...
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 ...
#Go
Go
start := &Ele{"tacos", nil} end := start.Append("burritos") end = end.Append("fajitas") end = end.Append("enchilatas") for iter := start; iter != nil; iter = iter.Next { fmt.Println(iter) }
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 ...
#Haskell
Haskell
map (>5) [1..10] -- [False,False,False,False,False,True,True,True,True,True]   map (++ "s") ["Apple", "Orange", "Mango", "Pear"] -- ["Apples","Oranges","Mangos","Pears"]   foldr (+) 0 [1..10] -- prints 55   traverse :: [a] -> [a] traverse list = map func list where func a = -- ...do something with 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...
#Forth
Forth
\ Create the list and some list elements create A 0 , char A , create B 0 , char B , create C 0 , char C ,
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...
#Fortran
Fortran
elemental subroutine addAfter(nodeBefore,value) type (node), intent(inout) :: nodeBefore real, intent(in) :: value type (node), pointer :: newNode   allocate(newNode) newNode%data = value newNode%next => nodeBefore%next nodeBefore%next => newNode end subroutine addAfter
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. ...
#Common_Lisp
Common Lisp
(defun test-sleep () (let ((seconds (read))) (format t "Sleeping...~%") (sleep seconds) (format t "Awake!~%")))   (test-sleep)
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. ...
#D
D
import std.stdio, core.thread;   void main() { write("Enter a time to sleep (in seconds): ");   long secs; readf(" %d", &secs);   writeln("Sleeping..."); Thread.sleep(dur!"seconds"(secs)); writeln("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 ...
#uBasic.2F4tH
uBasic/4tH
PRINT "Bubble sort:" n = FUNC (_InitArray) PROC _ShowArray (n) PROC _Bubblesort (n) PROC _ShowArray (n) PRINT   END   _Bubblesort PARAM(1) ' Bubble sort LOCAL (2)   DO b@ = 0 FOR c@ = 1 TO a@-1 IF @(c@-1) > @(c@) THEN PROC _Swap (c@, c@-1) : b@ = c@ NEXT a@ = b@ U...
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...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Append[{}, x] -> {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...
#Modula-2
Modula-2
TYPE Link = POINTER TO LinkRcd; LinkRcd = RECORD Next: Link; Data: INTEGER END;
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...
#Modula-3
Modula-3
TYPE Link = REF LinkRcd; LinkRcd = RECORD Next: Link; Data: INTEGER END;
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.
#AutoHotkey
AutoHotkey
; Create simple windowed application Gui, Add, Text, vTextCtl, There have been no clicks yet ; add a Text-Control Gui, Add, Button, gButtonClick xm, click me ; add a Button-Control Gui, Show, , Simple windowed application ; show the Window Return ; end of the auto-execute section   ButtonClick: ; the subroutin...
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 ...
#Icon_and_Unicon
Icon and Unicon
procedure main () ns := Node(1, Node(2, Node (3))) until /ns do { # repeat until ns is null write (ns.value) ns := ns.successor } 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 ...
#J
J
foo"0 {:"1 list
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...
#FreeBASIC
FreeBASIC
sub insert_ll_int( anchor as ll_int ptr, ins as ll_int ptr) ins->nxt = anchor->nxt anchor->nxt = ins end sub
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...
#Go
Go
package main   import "fmt"   type Ele struct { Data interface{} Next *Ele }   func (e *Ele) insert(data interface{}) { if e == nil { panic("attept to modify nil") } e.Next = &Ele{data, e.Next} }   func (e *Ele) printList() { if e == nil { fmt.Println(nil) return } ...
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. ...
#DCL
DCL
$ amount_of_time = p1 ! hour[:[minute][:[second][.[hundredth]]]] $ write sys$output "Sleeping..." $ wait 'amount_of_time $ write sys$output "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. ...
#DBL
DBL
; ; Sleep for DBL version 4 by Dario B. ; PROC ;------------------------------------------------------------------ XCALL FLAGS (0007000000,1)  ;Suppress STOP message   OPEN(1,O,'TT:') DISPLAY (1,"Sleeping...",10) SLEEP 10  ;Sleep for 10 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 ...
#Unicon
Unicon
rm -f _sortpass   reset() { test -f _tosort || mv _sortpass _tosort }   bpass() { (read a; read b test -n "$b" -a "$a" && ( test $a -gt $b && (reset; echo $b; (echo $a ; cat) | bpass ) || (echo $a; (echo $b ; cat) | bpass ) ) || echo $a) }   bubblesort() { cat > _tosort while test -f _tosort 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...
#Nanoquery
Nanoquery
class link declare data declare next end
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...
#Nim
Nim
type   Node[T] = ref object next: Node[T] data: T   SinglyLinkedList[T] = object head, tail: Node[T]   proc newNode[T](data: T): Node[T] = Node[T](data: data)   proc append[T](list: var SinglyLinkedList[T]; node: Node[T]) = if list.head.isNil: list.head = node list.tail = node else: li...
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...
#Objective-C
Objective-C
#import <Foundation/Foundation.h>   @interface RCListElement<T> : NSObject { RCListElement<T> *next; T datum; } - (RCListElement<T> *)next; - (T)datum; - (RCListElement<T> *)setNext: (RCListElement<T> *)nx; - (void)setDatum: (T)d; @end   @implementation RCListElement - (RCListElement *)next { return next; } - (id...
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.
#AutoIt
AutoIt
  #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Local $GUI = GUICreate("Clicks", 280, 50, (@DesktopWidth - 280) / 2, (@DesktopHeight - 50) / 2) Local $lblClicks = GUICtrlCreateLabel("There have been no c...
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 ...
#Java
Java
LinkedList<Type> list = new LinkedList<Type>();   for(Type i: list){ //each element will be in variable "i" System.out.println(i); }
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 ...
#JavaScript
JavaScript
LinkedList.prototype.traverse = function(func) { func(this); if (this.next() != null) this.next().traverse(func); }   LinkedList.prototype.print = function() { this.traverse( function(node) {print(node.value())} ); }   var head = createLinkedListFromArray([10,20,30,40]); head.print();
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...
#Groovy
Groovy
class NodeList { private enum Flag { FRONT } private ListNode head void insert(value, insertionPoint=Flag.FRONT) { if (insertionPoint == Flag.FRONT) { head = new ListNode(payload: value, next: head) } else { def node = head while (node.payload != insertion...
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...
#Haskell
Haskell
insertAfter a b (c:cs) | a==c = a : b : cs | otherwise = c : insertAfter a b cs insertAfter _ _ [] = error "Can't insert"
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. ...
#Delphi
Delphi
program SleepOneSecond;   {$APPTYPE CONSOLE}   uses SysUtils;   var lTimeToSleep: Integer; begin if ParamCount = 0 then lTimeToSleep := 1000 else lTimeToSleep := StrToInt(ParamStr(1)); WriteLn('Sleeping...'); Sleep(lTimeToSleep); // milliseconds WriteLn('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. ...
#Diego
Diego
begin_instuct(sleepTime); ask_human()_first()_msg(Enter number of seconds to sleep: )_var(sleepSecs)_me(); set_decision(asynchronous)_me(); me_msg(Sleeping...); me_sleep[sleepSecs]_unit(secs); me_msg(Awake!); reset_decision()_me(); end_instruct(sleepTime);   exec_instruct(sleepTime)_...
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 ...
#UnixPipes
UnixPipes
rm -f _sortpass   reset() { test -f _tosort || mv _sortpass _tosort }   bpass() { (read a; read b test -n "$b" -a "$a" && ( test $a -gt $b && (reset; echo $b; (echo $a ; cat) | bpass ) || (echo $a; (echo $b ; cat) | bpass ) ) || echo $a) }   bubblesort() { cat > _tosort while test -f _tosort 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...
#OCaml
OCaml
type 'a list = Nil | Cons of 'a * 'a list
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...
#Oforth
Oforth
Collection Class new: LinkedList(data, mutable 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...
#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"   say "Manual...
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.
#B4J
B4J
  #Region Project Attributes #MainFormWidth: 593 #MainFormHeight: 179 #End Region   Sub Process_Globals Private fx As JFX Private MainForm As Form Private btnClickMe As Button Private lblClickCounter As Label Private nClicks As Int = 0 Private aPlurals() As Object = Array As Object(Array As String("has","cli...
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 ...
#jq
jq
  # Produce a stream of the items in the input SLL. def items: while(.; .next) | .item;   def to_singly_linked_list(s): reduce ([s]|reverse[]) as $item (null; {$item, next:.});   # If f evaluates to empty at any item, that item is removed; # if f evaluates to more than one item, all are added separately. def map_si...
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 ...
#Julia
Julia
Base.start(ll::LinkedList) = ll.head Base.done(ll::LinkedList{T}, st::AbstractNode{T}) where T = st isa EmptyNode Base.next(ll::LinkedList{T}, st::AbstractNode{T}) where T = st.data, st.next   lst = LinkedList{Int}() push!(lst, 1) push!(lst, 2) push!(lst, 3)   for n in lst print(n, " ") 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...
#Icon_and_Unicon
Icon and Unicon
  record Node (value, successor)   procedure insert_node (node, newNode) newNode.successor := node.successor node.successor := newNode 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...
#J
J
list=: 1 65,:_ 66 A=:0 NB. reference into list B=:1 NB. reference into list insertAfter=: monad define 'localListName localListNode localNewValue'=. y localListValue=: ".localListName localOldLinkRef=: <localListNode,0 localNewLinkRef=: #localListValue localNewNode=: (localOldLinkRef { localListValue)...
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. ...
#DIBOL-11
DIBOL-11
    START  ;Demonstrate the SLEEP function   RECORD SLEEPING , A8, "Sleeping"   RECORD WAKING , A6,"Awake"   PROC XCALL FLAGS (0007000000,1)  ;Suppress STOP message   OPEN(8,O,'TT:') WRITES(8,SLEEPING) SLEEP 30  ; Sleep for 30 second...
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. ...
#E
E
def sleep(milliseconds :int, nextThing) { stdout.println("Sleeping...") timer.whenPast(timer.now() + milliseconds, fn { stdout.println("Awake!") nextThing() }) }
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 ...
#Ursala
Ursala
#import nat   bubblesort "p" = @iNX ^=T ^llPrEZryPrzPlrPCXlQ/~& @l ~&aitB^?\~&a "p"?ahthPX/~&ahPfatPRC ~&ath2fahttPCPRC   #cast %nL   example = bubblesort(nleq) <362,212,449,270,677,247,567,532,140,315>
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...
#Pascal
Pascal
type PLink = ^TLink; TLink = record FNext: PLink; FData: integer; end;
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...
#Perl
Perl
my %node = ( data => 'say what', next => \%foo_node, ); $node{next} = \%bar_node; # mutable
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.
#BaCon
BaCon
OPTION GUI TRUE PRAGMA GUI gtk3   gui = GUIDEFINE(" \ { type=WINDOW name=window callback=delete-event title=\"Rosetta Code\" width-request=300 } \ { type=BOX name=box parent=window orientation=GTK_ORIENTATION_VERTICAL } \ { type=LABEL name=label parent=box height-request=50 label=\"There have been no clicks...
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.
#BBC_BASIC
BBC BASIC
INSTALL @lib$+"WINLIB2" INSTALL @lib$+"WINLIB5"   window% = FN_newdialog("Rosetta Code", 100, 100, 120, 52, 8, 1000) PROC_static(window%, "There have been no clicks yet", 100, 10, 10, 100, 14, 0) PROC_pushbutton(window%, "Click me", FN_setproc(PROCclick), 40, 30, 40, 16, 0) PROC_show...
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 ...
#Kotlin
Kotlin
fun main(args: Array<String>) { val list = IntRange(1, 50).toList()   // classic traversal: for (i in list) { print("%4d ".format(i)); if (i % 10 == 0) println() }   // list iterator: list.asReversed().forEach { print("%4d ".format(it)); if (it % 10 == 1) println() } }
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 ...
#Limbo
Limbo
implement Command;   include "sys.m"; sys: Sys;   include "draw.m";   include "sh.m";   init(nil: ref Draw->Context, nil: list of string) { sys = load Sys Sys->PATH;   l := list of {1, 2, 3, 4, 5};   # the unary 'tl' operator gets the tail of a list for (; l != nil; l = tl l) sys->print("%d\n", hd l); # the una...
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...
#Java
Java
void insertNode(Node<T> anchor_node, Node<T> new_node) { new_node.next = anchor_node.next; anchor_node.next = new_node; }
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...
#JavaScript
JavaScript
LinkedList.prototype.insertAfter = function(searchValue, nodeToInsert) { if (this._value == searchValue) { nodeToInsert.next(this.next()); this.next(nodeToInsert); } else if (this.next() == null) throw new Error(0, "value '" + searchValue + "' not found in linked list.") else ...
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. ...
#EGL
EGL
program Sleep type BasicProgram{}   // Syntax: sysLib.wait(time BIN(9,2) in)   function main() SysLib.writeStdout("Sleeping!"); sysLib.wait(15); // waits for 15 seconds SysLib.writeStdout("Awake!"); end   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. ...
#Eiffel
Eiffel
class APPLICATION inherit EXECUTION_ENVIRONMENT create make feature -- Initialization make -- Sleep for a given number of nanoseconds. do print ("Enter a number of nanoseconds: ") io.read_integer_64 print ("Sleeping...%N") sleep (io.las...
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 ...
#Vala
Vala
void swap(int[] array, int i1, int i2) { if (array[i1] == array[i2]) return; var tmp = array[i1]; array[i1] = array[i2]; array[i2] = tmp; }   void bubble_sort(int[] array) { bool flag = true; int j = array.length; while(flag) { flag = false; for (int i = 1; i < j; i++) { if (array[i] < a...