PSeInt SubProceso: examples of splitting a program
14 examples
How it works
A SubProceso groups instructions under a name so you can use them whenever you need. Instead of one long algorithm you get short pieces whose names say what they do: MostrarMenu, DibujarTablero, Intercambiar.
It's written outside the main Algoritmo, between SubProceso and FinSubProceso, and called by writing its name with parentheses. Parameters are the values it receives to work with.
By default parameters are passed by value (the SubProceso gets a copy). If you want it to change the original variable, as when swapping two numbers, declare the parameter Por Referencia.
Short example
The least you need to see it work. Copy it or open it in the editor.
SubProceso Linea(n) Definir i Como Entero Para i <- 1 Hasta n Hacer Escribir Sin Saltar "-" FinPara Escribir ""FinSubProcesoAlgoritmo Title Linea(20) Escribir " My first program" Linea(20)FinAlgoritmoWhat it prints:
-------------------- My first program--------------------
Opens in the browser editor, nothing to install.
Solved exercises
Each exercise comes with the full code, its flowchart and a sample run.
Bubble Sort
Sorts random numbers by swapping neighbors, and stops as soon as they're in order.
IntermediateSelection Sort
Finds the smallest of the remaining numbers and puts it in its place.
IntermediateInsertion Sort
Inserts each number among the sorted ones, like arranging cards in your hand.
IntermediateCounting Sort
Counts how many times each value appears, without comparing numbers.
IntermediateBinary Search
Finds a value in a sorted array by halving the range every step.
IntermediateLinear vs. Binary Search
Counts the comparisons each search needs on the same sorted list.
IntermediateBy Reference and by Value
Sorts three numbers by swapping them in subprocesses.
IntermediateModular Menu
A unit converter with a menu that keeps coming back.
IntermediateShell Sort
Insertion sort between far-apart elements, with a gap that shrinks every pass.
AdvancedMerge Sort
Splits the array in halves, sorts each one recursively and merges them.
AdvancedQuicksort
Picks a pivot, splits smaller from larger values and sorts each side recursively.
AdvancedHeap Sort
Arranges the array as a heap, then takes the largest out again and again.
AdvancedTowers of Hanoi
Solves the classic tower puzzle step by step.
AdvancedTic-Tac-Toe
The classic three-in-a-row game for two players.
Advanced
In the language reference
The instructions involved, explained one by one.
Other concepts
Codoritmo is an independent, open-source project inspired by PSeInt and compatible with its syntax. It is not affiliated with the PSeInt project. Official PSeInt website.