public linkedListOperationExecutor(
     ExecutionSequenceParameters eParams,
     LinkedList <LinkedListItem> list)
 {
     state = new LinkedListExecutionState(list);
     state.AddToKnownNodes(list.First);
     state.AddToKnownNodes(list.Last);
     this.eParams = eParams;
 }
Пример #2
0
        public override LinkedListNode <LinkedListItem> RunOnLinkedList(
            LinkedListExecutionState state)
        {
            LinkedListNode <LinkedListItem> successor = state.List.Last;

            while (successor.Previous != state.List.First &&
                   successor.Previous.Value.Deleted)
            {
                successor = successor.Previous;
            }
            return(state.AddingToKnownNodes(state.List.AddBefore(successor, new LinkedListItem(Value))));
        }
Пример #3
0
 public override bool RunOnLinkedList(
     LinkedListExecutionState state)
 {
     if (state.Current == null ||
         state.Current == state.List.First ||
         state.Current == state.List.Last ||
         state.Current.Value.Deleted)
     {
         return(false);
     }
     state.Current.Value.Delete();
     return(true);
 }
Пример #4
0
        public override object RunOnLinkedList(LinkedListExecutionState state)
        {
            LinkedListNode <LinkedListItem> current = state.Current;

            if (current != null &&
                current != state.List.First &&
                current != state.List.Last)
            {
                current.Value = current.Value.NewWithData(
                    current.Value.Data.NewWithValue(value));
            }
            return(null);
        }
        // ReSharper disable once RedundantAssignment
        public override LinkedListNode <LinkedListItem> RunOnLinkedList(
            LinkedListExecutionState state)
        {
            LinkedListNode <LinkedListItem> last = state.List.Last;

            do
            {
                last = last.Previous;
            }while (last != state.List.First && last.Value.Deleted);
            if (last == state.List.First)
            {
                return(null);
            }
            last.Value.Delete();
            return(state.AddingToKnownNodes(last));
        }
Пример #6
0
        RunOnLinkedList(
            LinkedListExecutionState state)
        {
            LinkedListNode <LinkedListItem> current = state.Current;

            if (current == null || current == state.List.First)
            {
                return(null);
            }
            LinkedListNode <LinkedListItem> successor = current;

            while (successor.Previous.Value.Deleted)
            {
                successor = successor.Previous;
            }
            return(state.AddingToKnownNodes(state.List.AddBefore(successor, new LinkedListItem(Value))));
        }
Пример #7
0
        public override ListItemData RunOnLinkedList(
            LinkedListExecutionState state)
        {
            if (state.Current == null || state.Current.Value.IsDummy)
            {
                return(null);
            }
            ListItemData prevalentData = state.Current.Value.Data;

            if (prevalentData.Value != oldValue)
            {
                return(prevalentData);
            }
            state.Current.Value =
                state.Current.Value.NewWithData(
                    prevalentData.NewWithValue(newValue));
            return(prevalentData);
        }
Пример #8
0
        public override object RunOnLinkedList(
            LinkedListExecutionState state)
        {
            LinkedListNode <LinkedListItem> current = state.Current;

            if (current == null || current == state.List.Last)
            {
                current = state.List.Last;
            }
            else
            {
                do
                {
                    current = current.Next;
                } while (current != null && current.Value.Deleted);
            }
            state.Current = current;
            return(null);
        }
Пример #9
0
        public override object RunOnLinkedList(
            LinkedListExecutionState state)
        {
            LinkedListNode <LinkedListItem> previous;

            if (state.Current == null || state.Current == state.List.First)
            {
                previous = state.List.First;
            }
            else
            {
                previous = state.Current.Previous;
                while (previous.Value.Deleted)
                {
                    previous = previous.Previous;
                }
            }
            state.Current = previous;
            return(null);
        }
Пример #10
0
        public override LinkedListNode <LinkedListItem> RunOnLinkedList(LinkedListExecutionState state)
        {
            if (state.Current == null ||
                state.Current == state.List.Last ||
                state.Current == state.List.First)
            {
                return(null);
            }
            ListItemData oldData = state.Current.Value.Data;

            if (oldData.Value != prevalentValue ||
                state.Current.Value.Deleted)
            {
                state.AddToKnownNodes(null);
                return(null);
            }
            return
                (state.AddingToKnownNodes(
                     state.List.AddAfter(state.Current, new LinkedListItem(Value))));
        }
        public override LinkedListNode <LinkedListItem> RunOnLinkedList(
            LinkedListExecutionState state)
        {
            LinkedListNode <LinkedListItem> current = state.Current;

            if (current == null || current == state.List.Last)
            {
                return(null);
            }

            if (!current.Value.Deleted)
            {
                return(state.AddingToKnownNodes(
                           state.List.AddAfter(current, new LinkedListItem(Value))));
            }
            LinkedListNode <LinkedListItem> prev = current;

            while (prev.Previous.Value.Deleted)
            {
                prev = prev.Previous;
            }
            return(state.AddingToKnownNodes(state.List.AddBefore(prev, new LinkedListItem(Value))));
        }
Пример #12
0
 public override ListItemData RunOnLinkedList(LinkedListExecutionState state)
 {
     return(state.Current == null || state.Current.Value.IsDummy ?
            null :
            state.Current.Value.Data);
 }
 public override object RunOnLinkedList(LinkedListExecutionState state)
 {
     return(run(state));
 }
Пример #14
0
 public override LinkedListNode <LinkedListItem> RunOnLinkedList(
     LinkedListExecutionState state)
 {
     return(state.AddingToKnownNodes(
                state.List.AddAfter(state.List.First, new LinkedListItem(Value))));
 }