“This is the 9th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”
Hello everyone, I am quick-frozen fish 🐟, a front end of water system 💦, like colorful whistle 💐, continuous sand sculpture 🌲, I am a good brother of the next door Cold grass Whale, I just started to write an article. If you like my article, you can follow ➕ to like it, inject energy into me, and grow with me
Preface 🌧 ️
Algorithms are unfamiliar and familiar to the front-end people, and often we don’t value them as much as the back-end engineers do. But in fact, algorithms have an unshakable position for every programmer.
Because the development process is to convert the actual problem into the computer can recognize the instructions, that is, “data structure” said, “design the data structure, in the application of algorithms on the line”.
The quality of writing instructions will directly affect the performance of the program, and instructions are composed of data structure and algorithm, so the design of data structure and algorithm basically determines the quality of the final program.
In addition, when reading the source code, the lack of understanding of algorithms and data structures makes it difficult to understand why the author wrote the way he did.
In today’s environment, algorithms have become an indispensable skill for front-end engineers. If we want to move beyond being application engineers writing business code, we need to understand algorithms and data structures.
Of course, learning is also focused, as the front end we do not need to fully grasp the algorithm like back-end development, some of the more partial, not practical type and solution method, as long as a little understanding.
Bubble sort idea 🦀
- Compare all adjacent elements and swap them if the first is larger than the second.
- After one round, I guarantee that the last number is the largest.
- Do n-1 rounds to complete the sorting.
Bubble sort animation 🌵
Source 🔥
Array.prototype.bubbleSort=function(){
for(let i=0; i<this.length-1; i++){for(let j=0; j<this.length-1-i; j++){if(this[j]>this[j+1]) {const temp=this[j]
this[j]=this[j+1]
this[j+1]=temp
}
}
}
}
const array=[5.4.3.2.1]
array.bubbleSort()
Copy the code
Time complexity :O(n^2)
Conclusion 🌞
So fish fish LeetCode algorithm article “LeetCode” bubble sort ⚡ ️ ended, algorithm this thing no shortcuts, only more writing practice more, more, actually very simple, the purpose of the article is to push myself to accomplish algorithm practice and summarize and output, food not food is not important, but love 🔥, like everyone to be able to like my essay, Also hope to know more like-minded friends through this article, if you also like to toss, welcome to add my friend, sand sculpture, progress together.
Making 🤖 : sudongyu
Personal blog 👨💻: Frozen fish blog
Vx 👦 : sudongyuer
Write in the last
Guys, if you like my words, give 🐟🐟 a thumbs up 👍 or follow ➕ to support me the most.
Add me on wechat: Sudongyuer, invite you into the group and learning the front together, become a better engineer ~ (group of qr code here – > front to go to bed early, qr code has expired, see the links to the boiling point in the comments, I will put the latest qr code in the comments section, of course, can also add me WeChat I pull you into the group, after all, I also am interesting front end, I also not bad 🌟 ~