Пример #1
0
        private void ArrayPush(ref SnapShotStruct[] snapshotStack, SnapShotStruct currentSnapshot)
        {
            SnapShotStruct[] newSnapshootStack = new SnapShotStruct[snapshotStack.Length + 1];
            for (int i = 0; i < snapshotStack.Length; i++)
                newSnapshootStack[i] = snapshotStack[i];
            newSnapshootStack[snapshotStack.Length] = currentSnapshot;

            snapshotStack = newSnapshootStack;
        }
Пример #2
0
        private void ArrayPop(ref SnapShotStruct[] snapshotStack, int index = 0)
        {
            SnapShotStruct[] newSnapshootStack = new SnapShotStruct[snapshotStack.Length - 1];
            for (int i = 0, j = 0; i < newSnapshootStack.Length; i++, j++)
            {
                if (i == index)
                    j++;
                newSnapshootStack[i] = snapshotStack[j];
            }

            snapshotStack = newSnapshootStack;
        }
Пример #3
0
        public string GetAllSteps(int n)
        {
            string allSteps = "";

            int retVal = 0;

            SnapShotStruct[] snapshotStack = new SnapShotStruct[0];

            SnapShotStruct currentSnapshot;
            currentSnapshot.n = n;
            currentSnapshot.test = 0;
            currentSnapshot.stage = 0;
            ArrayPush(ref snapshotStack, currentSnapshot);

            while (snapshotStack.Length != 0)
            {
                currentSnapshot = snapshotStack[0];
                ArrayPop(ref snapshotStack);

                switch (currentSnapshot.stage)
                {
                    case 0:
                        if (currentSnapshot.n > 0)
                        {
                            allSteps += (allSteps.Length > 0 ? ", " : "") + currentSnapshot.n;

                            currentSnapshot.stage = 1;
                            ArrayPush(ref snapshotStack, currentSnapshot);
                            SnapShotStruct newSnapshot;
                            newSnapshot.n = currentSnapshot.n - 1;// descrestem
                            newSnapshot.test = 0;
                            newSnapshot.stage = 0;
                            ArrayPush(ref snapshotStack, newSnapshot);
                            continue;
                        }

                        retVal = 0;
                        continue;
                        //break;
                    case 1:
                        currentSnapshot.test = retVal;
                        currentSnapshot.test--;

                        retVal = currentSnapshot.test;
                        continue;
                        //break;
                }

            }

            return allSteps;
        }
Пример #4
0
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        private static List <object> GetNETObjects(string RAWText)
        {
            var Results = new List <object>();
            Stack <SnapShotStruct> snapshotStack   = new Stack <SnapShotStruct>();
            SnapShotStruct         currentSnapshot = new SnapShotStruct();

            currentSnapshot.RAWText           = RAWText;
            currentSnapshot.Results           = Results;
            currentSnapshot.Counter           = 0;
            currentSnapshot.CurrentObjectBool = false;
            currentSnapshot.CurrentObject     = string.Empty;
            currentSnapshot.stage             = 0;
            snapshotStack.Push(currentSnapshot);
            while (snapshotStack.Count > 0)
            {
                currentSnapshot = snapshotStack.Pop();
                if (currentSnapshot.stage == 0)
                {
                    currentSnapshot.stage = 1;
                    if (currentSnapshot.RAWText.StartsWith("["))
                    {
                        currentSnapshot.RAWText = currentSnapshot.RAWText.Remove(0, 1);
                        currentSnapshot.RAWText = currentSnapshot.RAWText.Remove(currentSnapshot.RAWText.Length - 1, 1);
                    }
                    for (int i = 0; i < currentSnapshot.RAWText.Length; i++)
                    {
                        if (currentSnapshot.RAWText[i].Equals('['))
                        {
                            currentSnapshot.Counter++;
                        }
                        if (currentSnapshot.RAWText[i].Equals(']'))
                        {
                            currentSnapshot.Counter--;
                        }
                        if (!currentSnapshot.RAWText[i].Equals(',') || (currentSnapshot.Counter > 0))
                        {
                            currentSnapshot.CurrentObject += currentSnapshot.RAWText[i];
                        }
                        if ((currentSnapshot.Counter == 0))
                        {
                            if (currentSnapshot.RAWText[i].Equals(',') || (i == (currentSnapshot.RAWText.Length - 1)))
                            {
                                if (currentSnapshot.CurrentObject.Contains("["))
                                {
                                    currentSnapshot.Results.Add(new List <object>());
                                    SnapShotStruct newSnapshot;
                                    newSnapshot.RAWText           = currentSnapshot.CurrentObject;
                                    newSnapshot.Results           = (List <object>)currentSnapshot.Results[currentSnapshot.Results.Count - 1];
                                    newSnapshot.Counter           = 0;
                                    newSnapshot.CurrentObjectBool = false;
                                    newSnapshot.CurrentObject     = string.Empty;
                                    newSnapshot.stage             = 0;
                                    snapshotStack.Push(newSnapshot);
                                }
                                else if ((currentSnapshot.CurrentObject.Split('.').Length < 3) && (int.TryParse(currentSnapshot.CurrentObject.Split('.')[0], out currentSnapshot.Counter)))
                                {
                                    currentSnapshot.Results.Add(currentSnapshot.Counter);
                                    currentSnapshot.Counter = 0;
                                }
                                else if (bool.TryParse(currentSnapshot.CurrentObject, out currentSnapshot.CurrentObjectBool))
                                {
                                    currentSnapshot.Results.Add(currentSnapshot.CurrentObjectBool);
                                    currentSnapshot.CurrentObjectBool = false;
                                }
                                else if (!currentSnapshot.CurrentObject.Equals("<null>", StringComparison.Ordinal) && !currentSnapshot.CurrentObject.Equals("<NULL-object>", StringComparison.Ordinal) && !currentSnapshot.CurrentObject.Equals("any", StringComparison.Ordinal))
                                {
                                    currentSnapshot.Results.Add(currentSnapshot.CurrentObject);
                                }
                                else
                                {
                                    currentSnapshot.Results.Add(null);
                                }
                                currentSnapshot.CurrentObject = string.Empty;
                            }
                        }
                    }
                }
            }
            return(Results);
        }