Veröffentlicht von & unter ColdFusion.

A ring array, also known as a circular array, is a data structure that behaves like an array but the elements are connected in a circular fashion. In other words, the last element of the array is followed by the first element, forming a loop.

Here’s an example of how you can implement a ring array for Coldfusion:

<cfset stack = []>
<cfset stackSize = 5>

<cfset push("Vater")>
<cfset push("Mutter")>
<cfset push("Kind")>
<cfset push("hund")>

<cfset push("Bolle")>
<cfset push("Alien")>

<cfset push("Fussel")>
<cfset push("Barbie")>

<cffunction name="push" output="false" hint="Push a value onto the stack">
  <cfargument name="value" required="true">

  <cfif arrayLen(stack) EQ stackSize>
    <cfset arrayDeleteAt(stack, 1)>
    <cfset arrayAppend(stack, arguments.value)>
    <cfset arrayAppend(stack, arguments.value)>

<cffunction name="pop" output="true" hint="Pop a value off the top of the stack">
  <cfreturn arrayDeleteAt(stack, arrayLen(stack))>

<cffunction name="peek" output="true" hint="Peek at the top value on the stack">
  <cfreturn stack[arrayLen(stack)]>

<cffunction name="rotate" output="false" hint="Rotate the stack">
  <cfif arrayLen(stack) GT 0>
    <cfset arrayPrepend(stack, pop())>

<cfdump var="#stack#">
<cfdump var="#peek()#">