ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Queue, stack, list and array functions / Queue, stack and list functions
  • WLanguage properties that can be used with the Stack type
  • WLanguage functions for managing stacks
  • The stacks and the multithread
  • Browsing the stacks
  • Special cases
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
A Stack variable is a structured type that is used to group a set of elements of the same type. The elements are added at the end of stack and they are retrieved from the most recent one.
For example, if the elements are added in the following order: 1, 2, 3, they will be retrieved in the following order: 3, 2, 1.
Example
MyStack is Stack of int
 
// Push the values 1, 2 and 3
Push(MyStack, 1)
Push(MyStack, 2)
Push(MyStack, 3)
 
// Display the trace: 3, 2, 1
x is int
WHILE Pop(MyStack, x)
Trace(x)
END
Syntax

Declaring and initializing a stack Hide the details

<Stack name> is Stack of <Type of stack elements>
<Stack name>:
Name of Stack variable to declare.
<Type of stack elements>:
Type of the elements found in the stack.
All types of variables can be used including the arrays, the associative arrays, the queues, the stacks and the lists. For example:
<variable> is stack of arrays of int

<variable> is stack of fixed arrays of 5 int

<variable> is stack of associative arrays of int

<variable> is stack of queues of int

<variable> is stack of stacks of int

<variable> is stack of lists of int
Remarks

WLanguage properties that can be used with the Stack type

The following properties can be used to handle a Stack variable.
Property name
Effect
AdditionCompletedReturns and modifies the addition mode of elements.
This property is used for the multithread management.
Empty
  • True if the stack is empty,
  • False otherwise.
NbPendingThreadReturns the number of pending threads.
This property is used for the multithread management.
OccurrenceReturns the number of stack occurrences.

WLanguage functions for managing stacks

The following functions can be used to handle a Stack variable.
DeleteAllDeletes all the elements:
  • from a one-dimensional or two-dimensional WLanguage array.
  • from an associative array.
  • from an advanced array property (array of gglCalendar events, etc.).
  • from a WLanguage queue.
  • from a WLanguage stack.
  • from a WLanguage list.
DeserializeDeserializes a buffer or a character string containing the data from a class, structure, array (including an associative array), queue, stack, list or advanced variable, as well as their subelements.
PopPops an element from a stack.
PushPushes an element onto the stack.
SerializeTransforms the following elements into a specific format:
  • a structure (and its subelements),
  • a class (and its subelements),
  • an array (including the associative arrays),
  • a queue,
  • a stack,
  • a list.
StackInfoRetrieves the characteristics of a stack: types of elements and number of elements.

The stacks and the multithread

The management of multithread is taken into account when adding and deleting an element (Push and Pop).
You also have the ability to use properties during a multithread management but the result is not permanent. For example:
IF MyStack.Occurrence > 0 THEN
// The stack may be empty when the thread reaches this point
END

Browsing the stacks

The FOR EACH syntax can be used to browse the stacks. The elements are browsed in pop order that is the reverse order of the push order.
The syntax used corresponds to the one used for the arrays:
FOR EACH [ELEMENT] <Variable> [, <Counter> [, <Counter>]] OF <Stack>
...
END
The elements can be modified during the browse. If the stack is modified during a browse, the elements browsed will be the ones found when the browse was initialized:
  • the elements pushed after the initialization of the browse will not be browsed.
  • the elements popped after the initialization of the browse will still be browsed.

Special cases

  • In the debugger, the content of the stack is displayed in pop order.
  • A stack can be used to type a procedure parameter.
  • A stack can be copied by the operator '='. You also have the ability to copy a class or structure instance containing a stack.
  • A stack can be initialized by a list of elements in push order.
Minimum version required
  • Version 14
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 01/26/2023

Send a report | Local help