Skip to content

Commit

Permalink
Add generic_list_reverse example
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Feb 1, 2025
1 parent 98d450f commit 7099e12
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/xtd.core.examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
* [generic_list_convert_all](generic_Collections/generic_list_convert_all/README.md) shows how to use [xtd::collections::generic::list::convert_all](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1collections_1_1generic_1_1list.html) method.
* [generic_list_exists](generic_Collections/generic_list_exists/README.md) shows how to use [xtd::collections::generic::list::exists](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1collections_1_1generic_1_1list.html) method.
* [generic_list_for_each](generic_Collections/generic_list_for_each/README.md) shows how to use [xtd::collections::generic::list::for_each](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1collections_1_1generic_1_1list.html) method.
* [generic_list_reverse](generic_Collections/generic_list_reverse/README.md) shows how to use [xtd::collections::generic::list::reverse](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1collections_1_1generic_1_1list.html) method.

## [Guid](guid/README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ add_projects(
generic_list_convert_all
generic_list_exists
generic_list_for_each
generic_list_reverse
)
1 change: 1 addition & 0 deletions examples/xtd.core.examples/generic_collections/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [generic_list_convert_all](generic_list_convert_all/README.md) shows how to use [xtd::collections::generic::list::convert_all](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1collections_1_1generic_1_1list.html) method.
* [generic_list_exists](generic_list_exists/README.md) shows how to use [xtd::collections::generic::list::exists](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1collections_1_1generic_1_1list.html) method.
* [generic_list_for_each](generic_list_for_each/README.md) shows how to use [xtd::collections::generic::list::for_each](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1collections_1_1generic_1_1list.html) method.
* [generic_list_reverse](generic_list_reverse/README.md) shows how to use [xtd::collections::generic::list::reverse](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1collections_1_1generic_1_1list.html) method.

## Build and run any project

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.20)

project(generic_list_reverse)
find_package(xtd REQUIRED)
add_sources(README.md src/generic_list_reverse.cpp)
target_type(CONSOLE_APPLICATION)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# generic_list_reverse

Shows how to use [xtd::collections::generic::list::reverse](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1collections_1_1generic_1_1list.html) method.

## Sources

[src/generic_list_reverse.cpp](src/generic_list_reverse.cpp)

[CMakeLists.txt](CMakeLists.txt)

## Build and run

Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following:

```cmake
xtdc run
```

## Output

```
Pachycephalosaurus
Parasauralophus
Mamenchisaurus
Amargasaurus
Coelophysis
Oviraptor
Oviraptor
Coelophysis
Amargasaurus
Mamenchisaurus
Parasauralophus
Pachycephalosaurus
Oviraptor
Parasauralophus
Mamenchisaurus
Amargasaurus
Coelophysis
Pachycephalosaurus
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <xtd/xtd>

using namespace xtd;
using namespace xtd::collections::generic;

class example {
public:
static auto main() -> void {
auto dinosaurs = list<string> {};

dinosaurs.add("Pachycephalosaurus");
dinosaurs.add("Parasauralophus");
dinosaurs.add("Mamenchisaurus");
dinosaurs.add("Amargasaurus");
dinosaurs.add("Coelophysis");
dinosaurs.add("Oviraptor");

console::write_line();
for (const auto& dinosaur : dinosaurs)
console::write_line(dinosaur);

dinosaurs.reverse();

console::write_line();
for (const auto& dinosaur : dinosaurs)
console::write_line(dinosaur);

dinosaurs.reverse(1, 4);

console::write_line();
for (const auto& dinosaur : dinosaurs)
console::write_line(dinosaur);
}
};

startup_(example::main);

// This code produces the following output :
//
//
// Pachycephalosaurus
// Parasauralophus
// Mamenchisaurus
// Amargasaurus
// Coelophysis
// Oviraptor
//
// Oviraptor
// Coelophysis
// Amargasaurus
// Mamenchisaurus
// Parasauralophus
// Pachycephalosaurus
//
// Oviraptor
// Parasauralophus
// Mamenchisaurus
// Amargasaurus
// Coelophysis
// Pachycephalosaurus

0 comments on commit 7099e12

Please sign in to comment.