代码编写规范

💡 代码编写规范用于提升代码质量、增加代码可读性、可维护性

  1. idea 安装 Alibaba Java Coding GuideLines规范化插件
  2. 判断true or false的时候必须关注 类型是Boolean类型还是boolean类型

代码review规范

💡 Tips:代码review可以减少代码的逻辑错误

代码自测规范

💡 Tips:输入/代码块或点击上方工具栏点击上方工具栏image.png,选择「代码块」、插入代码卡片。

代码块同时支持多种颜色主题:

  1. export default class QuickSort extends Sort {
  2. sort(originalArray) {
  3. const array = [...originalArray];
  4. if (array.length <= 1) {
  5. return array;
  6. }
  7. // Init left and right arrays.
  8. const leftArray = [];
  9. const rightArray = [];
  10. // Take the first element of array as a pivot.
  11. const pivotElement = array.shift();
  12. const centerArray = [pivotElement];
  13. // Split all array elements between left, center and right arrays.
  14. while (array.length) {
  15. const currentElement = array.shift();
  16. // Call visiting callback.
  17. this.callbacks.visitingCallback(currentElement);
  18. if (this.comparator.equal(currentElement, pivotElement)) {
  19. centerArray.push(currentElement);
  20. } else if (this.comparator.lessThan(currentElement, pivotElement)) {
  21. leftArray.push(currentElement);
  22. } else {
  23. rightArray.push(currentElement);
  24. }
  25. }
  26. // Sort left and right arrays.
  27. const leftArraySorted = this.sort(leftArray);
  28. const rightArraySorted = this.sort(rightArray);
  29. return leftArraySorted.concat(centerArray, rightArraySorted);
  30. }
  31. }
  1. export default class QuickSort extends Sort {
  2. sort(originalArray) {
  3. const array = [...originalArray];
  4. if (array.length <= 1) {
  5. return array;
  6. }
  7. // Init left and right arrays.
  8. const leftArray = [];
  9. const rightArray = [];
  10. // Take the first element of array as a pivot.
  11. const pivotElement = array.shift();
  12. const centerArray = [pivotElement];
  13. // Split all array elements between left, center and right arrays.
  14. while (array.length) {
  15. const currentElement = array.shift();
  16. // Call visiting callback.
  17. this.callbacks.visitingCallback(currentElement);
  18. if (this.comparator.equal(currentElement, pivotElement)) {
  19. centerArray.push(currentElement);
  20. } else if (this.comparator.lessThan(currentElement, pivotElement)) {
  21. leftArray.push(currentElement);
  22. } else {
  23. rightArray.push(currentElement);
  24. }
  25. }
  26. // Sort left and right arrays.
  27. const leftArraySorted = this.sort(leftArray);
  28. const rightArraySorted = this.sort(rightArray);
  29. return leftArraySorted.concat(centerArray, rightArraySorted);
  30. }
  31. }
  1. export default class QuickSort extends Sort {
  2. sort(originalArray) {
  3. const array = [...originalArray];
  4. if (array.length <= 1) {
  5. return array;
  6. }
  7. // Init left and right arrays.
  8. const leftArray = [];
  9. const rightArray = [];
  10. // Take the first element of array as a pivot.
  11. const pivotElement = array.shift();
  12. const centerArray = [pivotElement];
  13. // Split all array elements between left, center and right arrays.
  14. while (array.length) {
  15. const currentElement = array.shift();
  16. // Call visiting callback.
  17. this.callbacks.visitingCallback(currentElement);
  18. if (this.comparator.equal(currentElement, pivotElement)) {
  19. centerArray.push(currentElement);
  20. } else if (this.comparator.lessThan(currentElement, pivotElement)) {
  21. leftArray.push(currentElement);
  22. } else {
  23. rightArray.push(currentElement);
  24. }
  25. }
  26. // Sort left and right arrays.
  27. const leftArraySorted = this.sort(leftArray);
  28. const rightArraySorted = this.sort(rightArray);
  29. return leftArraySorted.concat(centerArray, rightArraySorted);
  30. }
  31. }