private void Sort(List <int> list) { int heapSize = list.Count; // build the heap for (int i = heapSize / 2; i >= 0; i--) { Heapify(list, heapSize, i); } for (int i = heapSize - 1; i > 0; i--) { list.Swap(0, i); // we know the root is the next largest item. move it to the end SwapCallback?.Invoke(0, i); Heapify(list, i, 0); // rebuild the heap } }
private void Sort3(List <int> list) { int end = list.Count; while (end > 0) { int newEnd = 0; // keep track of the highest index that's swapped for (int i = 1; i < end; i++) { if (list[i - 1] > list[i]) { list.Swap(i, i - 1); SwapCallback?.Invoke(i, i - 1); newEnd = i; } } end = newEnd; // we know everything beyond newEnd is in its final position } }
private void Sort1(List <int> list) { bool swapped = true; int end = list.Count; while (swapped) { swapped = false; for (int i = 1; i < end; i++) { if (list[i - 1] > list[i]) { list.Swap(i, i - 1); SwapCallback?.Invoke(i, i - 1); swapped = true; } } } }
private int Partition(List <int> list, int low, int high) { int p = list[high]; int i = low - 1; for (int j = low; j <= high - 1; j++) { if (list[j] <= p) { i++; list.Swap(i, j); SwapCallback?.Invoke(i, j); } } list.Swap(i + 1, high); SwapCallback?.Invoke(i + 1, high); return(i + 1); }
private void Sort2(List <int> list) { bool swapped = true; int end = list.Count; while (swapped) { swapped = false; for (int i = 1; i < end; i++) { if (list[i - 1] > list[i]) { list.Swap(i, i - 1); SwapCallback?.Invoke(i, i - 1); swapped = true; } } end--; // at the end of each pass, we know the element at end is in its final position } }
private void Heapify(List <int> list, int heapSize, int index) { int largest = index; // parent int left = (2 * index) + 1; // left child int right = (2 * index) + 2; // right child if (left < heapSize && list[left] > list[largest]) { largest = left; } if (right < heapSize && list[right] > list[largest]) { largest = right; } if (largest != index) { list.Swap(index, largest); SwapCallback?.Invoke(index, largest); Heapify(list, heapSize, largest); } }
private void Sort(List <int> list) { int count = list.Count; for (int i = 0; i < count - 1; i++) { int iMin = i; for (int j = i + 1; j < count; j++) { if (list[j] < list[iMin]) { iMin = j; } } if (iMin != i) { list.Swap(i, iMin); SwapCallback?.Invoke(i, iMin); } } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetTheme(Resource.Style.Theme_Normal); SetContentView(Resource.Layout.Editor); bottompanel = FindViewById <FrameLayout>(Resource.Id.selector); FindViewById <FloatingActionButton>(Resource.Id.savebtn).Click += Editor_Click; FindViewById <ImageButton>(Resource.Id.audiobtn).Click += Editor_Click1; FindViewById <ImageButton>(Resource.Id.helpbtn).Click += Editor_Click2; //selector: var fragmentTransaction = SupportFragmentManager.BeginTransaction(); allclipsfragment = new AllClipsFragment(AllClipsFragment.ClipViewMode.EDITING); fragmentTransaction.Add(Resource.Id.selector, allclipsfragment); fragmentTransaction.Commit(); (allclipsfragment as IImagePausable).Pause(); allclipsfragment.OnPreview += Fragment_OnPreview; allclipsfragment.OnChosen += Fragment_OnChosen; allclipsfragment.OnOpenIngest += IngestOpen; //recyclerview var listView = FindViewById <RecyclerView>(Resource.Id.editlist); var mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.Horizontal, false); _adapter = new SingleEditAdapter(this); _adapter.OnChange += _adapter_OnChange; _adapter.OnPreview += _adapter_OnPreview; _adapter.OnTrim += _adapter_OnTrim; _adapter.OnDelete += _adapter_OnDelete; _adapter.HasStableIds = true; listView.SetLayoutManager(mLayoutManager); listView.SetAdapter(_adapter); timeline = FindViewById <RecyclerView>(Resource.Id.timeline); var mLayoutManager1 = new LinearLayoutManager(this, LinearLayoutManager.Horizontal, false); timeline.SetLayoutManager(mLayoutManager1); _sliveradapter = new SliverEditAdapter(this); timeline.SetAdapter(_sliveradapter); preview = FindViewById <EditVideoView>(Resource.Id.edit_preview); //preview.OnEndOfVideo += Preview_OnEndOfVideo; preview.OnInPointChanged += Preview_OnInPointChanged; preview.OnOutPointChanged += Preview_OnOutPointChanged; preview.OnPositionChange += Preview_OnPositionChange; preview.HideDetails(); lefttimetotal = FindViewById <TextView>(Resource.Id.lefttimetotal); tracker = FindViewById <View>(Resource.Id.pos); ItemTouchHelper.Callback callback = new SwapCallback(this, _adapter, _sliveradapter); ItemTouchHelper touchHelper = new ItemTouchHelper(callback); touchHelper.AttachToRecyclerView(listView); EditorWizard.ShowWizard(this, false); //autosave function: autosaver = new BackgroundWorker(); autosaver.WorkerSupportsCancellation = true; autosaver.DoWork += Autosaver_DoWork; autosaver.RunWorkerAsync(); }