Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use common algorithms in C++ STL

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "C++ STL commonly used algorithms how to use", the article explains the content is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "C++ STL commonly used algorithms how to use" it!

Preface

The use of STL algorithm in C++ should include an algorithm header file # include

So that we can use this STL algorithm function.

Sort by sort ()

The Sort function is contained in the C++ standard library with a header file of # include. It is an efficient function specially used for sorting, and we can arrange the order quickly and easily when solving problems.

The sort () function takes three arguments (the first address of the array, the address that needs to end, and the arrangement)

The third arrangement may not be written, and the system will default from small to large.

Let's look at a real case.

1. If we want to sort from big to small, we don't have to write the third parameter.

Eg:

# include # include//sort () function required header file using namespace std; int main () {int a [10] = {4, 5, 10, 9, 8, 2, 1, 4, 0, 2, 1, 4, 0, 0, 3}; / / initialize the array for (int iMago

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report