The speed comparison of three legendary languages ​​(4)

xiaoxiao2021-03-06  20

Code C:

/ * * CREATED ON 2005-3-21 * /

/ ** * @Author jtzhu * / using system;

internal class NoSuchElementException: System.Exception {}; public class list {internal class Element {internal int datum; internal Element next; internal Element (int datum, Element next) {this.datum = datum; this.next = next;}}

internal class Iter {Element curr; internal Iter (Element head) {this.curr = head;!} internal bool hasNext () {return curr = null;} internal int next () {if (curr == null) throw new NoSuchElementException (); Int result = curr.datum; curr = curr.next; return result;}}; element head; element tail; list () {head = tail = null;} Bool iSempty () {return head == null; } Void purge () {element curr = head; element next; while (curr! = Null) {Next = curr.next; curr = next;

Head = tail = null;} void append ({== null) {head = tail = new element (datum, null);} else {tail.next = new element (datum, null); tail = tail.next;}} void extract (ISEMPTY ()) throw new nosuchelementexception (); element curr = head; element pre = null; while (curr! = null && curr.datum! = Datum) {Pre = curr; curr = curr.next;} if (curr == null) throw new nosuchelementexception (); if (curr == head) {ELSE = next;} else {pre.next;} else {pre.next;} else {pre.next; = curr.next;} if (curr == tail) tail = pre;} Void Assign {IF (this == Another) return; ipurn; itute = another.ITerator (); purge (); while .hasNext ()) {append (}}}}}}}}}}}}}}}}}}}}} Public static void main () {list from = new list (); list to = new list (); const INT length = 100000; const INNERLOOPS = 100; for (int i = 0; i

DateTime start, end; double timeuse; for (int i = 0; i <3; i ) {console.write ("loop" i ": / n"); timeuse = 0; for (int K = 0; K

Start = datetime.now; for (int J = length / 2; j <(length / 2 1000); j ) TO.EXTRACT (j); end = DATETIME.NOW; timeuse = (end-start) .totalmilliseConds; Console.write ("Extract:" 1000 / TimeUse "K / S / T");

TimeUse = 0; for (int K = 0; k

Compilation method:

CSC List.cs

转载请注明原文地址:https://www.9cbs.com/read-43956.html

New Post(0)