Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Sorted list implemenation using a stack and insertion sort
program SortedStack; type node = Record key : int64; next : ^node; end; const NO_OF_ELEMENTS = 100; var topPtr : ^node; i : int32; procedure init; begin topPtr := nil; end; function empty : boolean; begin empty := topPtr = nil; end; function top : int64; begin top := topPtr^.key; end; procedure push(key : int64); var newElement, temp : ^node; begin if empty then begin new(topPtr); topPtr^.key := key; topPtr^.next := nil; end else begin new(newElement); newElement^.key := key; if key <= topPtr^.key then begin newElement^.next := topPtr; topPtr := newElement; end else begin temp := topPtr; while (temp^.next <> nil) and (key > temp^.next^.key) do begin temp := temp^.next; end; newElement^.next := temp^.next; temp^.next := newElement; end; end; end; function pop : int64; var temp : ^node; begin if empty then pop := 0 else begin pop := top; temp := topPtr^.next; dispose(topPtr); topPtr := temp; end; end; begin init; Randomize; for i := 1 to NO_OF_ELEMENTS do begin push(random(1000)); end; for i := 1 to NO_OF_ELEMENTS do begin writeln(pop); end; end.
run
|
edit
|
history
|
help
0
Пиріжки
test29
TimeDemo
right angle triangle
nomer2
Задача 6.14 из учебника Грицановой (квартира)
Homework 10
practica 6 ejercicio 4
test19
Project Euler 21 - Amicable numbers