Ejemplo n.º 1
0
    // Driver Code
    public static void Main(String [] args)
    {
        /* Let us create two sorted linked
         * lists to test the methods
         * Created lists:
         *      llist1: 5->10->15,
         *      llist2: 2->3->20
         */
        MergeLists llist1 = new MergeLists();
        MergeLists llist2 = new MergeLists();

        // Node head1 = new Node(5);
        llist1.addToTheLast(new Node(5));
        llist1.addToTheLast(new Node(10));
        llist1.addToTheLast(new Node(15));

        // Node head2 = new Node(2);
        llist2.addToTheLast(new Node(2));
        llist2.addToTheLast(new Node(3));
        llist2.addToTheLast(new Node(20));


        llist1.head = new Gfg().sortedMerge(llist1.head,
                                            llist2.head);
        llist1.printList();
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Sorts the items on each rail and merges them into a single, sequential and ordered IList value
        /// where the ordering is determined by the given comparer.
        /// </summary>
        /// <typeparam name="T">The value type.</typeparam>
        /// <param name="source">The source IParallelFlowable instance.</param>
        /// <param name="comparer">The shared comparer used for determining the element ordering.</param>
        /// <returns>The new IFlowable instance.</returns>
        public static IFlowable <IList <T> > ToSortedList <T>(this IParallelFlowable <T> source, IComparer <T> comparer)
        {
            var a = new ParallelFlowableCollect <T, List <T> >(source, ListSupplier <T> .Instance, ListAdd <T> .Instance);
            Func <List <T>, IList <T> > f = list => { list.Sort(comparer); return(list); };
            var b = new ParallelFlowableMap <List <T>, IList <T> >(a, f);

            return(new ParallelFlowableReduceAll <IList <T> >(b, (u, v) => MergeLists <T> .Merge(u, v, comparer)));
        }
Ejemplo n.º 3
0
 public MergeListsTests()
 {
     this.historyProvider = Substitute.For <HistoryProviderBase>();
     this.processor       = new MergeLists(new ComparableSyncActionFactory(), this.historyProvider);
 }