struct product
{
string name;
int category;
string date;
string date_manufacture;
int shelf_life;
int price;
int count;
};
product products[] = {
{ "White bread", 1, "21.12.2022", "21.12.2022", 11, 100, 18 },
{ "wheat bread", 3, "21.12.2022", "21.12.2022", 9, 70, 118 },
{ "rye bread", 4, "21.12.2022", "21.12.2022", 16, 60, 161 },
{ "pretzel bread", 8, "21.12.2022", "21.12.2022", 18, 71, 111 },
{ " pite bread", 6, "21.12.2022", "21.12.2022", 3, 84, 121 },
{ "challah bread", 7, "21.12.2022", "21.12.2022", 21, 26, 131 },
{ "french bread", 10, "21.12.2022", "21.12.2022", 17, 34, 141 },
{ "croissant bread", 12, "21.12.2022", "21.12.2022", 1, 89, 17 },
{ "donut bread", 11, "21.12.2022", "21.12.2022", 22, 77, 9 },
{ "sweet bread", 13, "21.12.2022", "21.12.2022", 11, 44, 65 },
{ "italian bread", 14, "21.12.2022", "21.12.2022", 18, 76, 45 },
{ "russian bread", 16, "21.12.2022", "21.12.2022", 14, 82, 42 },
{ "african bread", 15, "21.12.2022", "21.12.2022", 13, 45, 93 },
{ "japan bread", 7, "21.12.2022", "21.12.2022", 17, 32, 64 },
{ "french bread", 9, "21.12.2022", "21.12.2022", 19, 99, 12 },
{ "belgian bread", 22, "21.12.2022", "21.12.2022", 19, 62, 35 },
{ "british bread", 17, "21.12.2022", "21.12.2022", 16, 53, 48 },
{ "american bread", 14, "21.12.2022", "21.12.2022", 14, 57, 27 },
{ "spanish_breath bread", 18, "21.12.2022", "21.12.2022", 12, 61, 86 },
{ "black bread", 21, "21.12.2022", "21.12.2022", 24, 34, 43 }
};
Как отсортировать данный массив структур по полю name по возрастанию и вывести в консоль получившийся отсортированный массив структур?
C/C++
Сложности с массивами структур c++
Проверяй первый символ (с индексом ноль), // при равенстве со следущим
то есть
product p[10];
// ***
string tmp;
int z;
bool change;
for(int x = 0; x < 9; x++)
for(int y = x + 1; y < 10; y++)
{
z = 0;
change = false;
while(z < p[x].name.length() && z < p[y].name)
{
if(p[x].name[z] > p[y].name[z])
{
tmp = p[x].name;
p[x].name = p[y].name;
p[y].name = tmp;
change = true;
break;
}
z++;
}
if(!change)
{
if( p[x].name.length() > p[y].name.length() )
{
tmp = p[x].name;
p[x].name = p[y].name;
p[y].name = tmp;
}
}
}
то есть
product p[10];
// ***
string tmp;
int z;
bool change;
for(int x = 0; x < 9; x++)
for(int y = x + 1; y < 10; y++)
{
z = 0;
change = false;
while(z < p[x].name.length() && z < p[y].name)
{
if(p[x].name[z] > p[y].name[z])
{
tmp = p[x].name;
p[x].name = p[y].name;
p[y].name = tmp;
change = true;
break;
}
z++;
}
if(!change)
{
if( p[x].name.length() > p[y].name.length() )
{
tmp = p[x].name;
p[x].name = p[y].name;
p[y].name = tmp;
}
}
}
Вадим Щёголев
Что там где // ***
#include
#include
#include
using namespace std;
struct product {
string name;
int category;
string date;
string date_manufacture;
int shelf_life;
int price;
int count;
private:
friend bool operator
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
using namespace std;
int main(){
struct product {
string name; int category; string date; string date_manufacture;
int shelf_life; int price; int count; };
product products[] = {
{ "white bread", 1, "21.12.2022", "21.12.2022", 11, 100, 18 },
{ "wheat bread", 3, "21.12.2022", "21.12.2022", 9, 70, 118 },
{ "rye bread", 4, "21.12.2022", "21.12.2022", 16, 60, 161 },
{ "pretzel bread", 8, "21.12.2022", "21.12.2022", 18, 71, 111 },
{ "pite bread", 6, "21.12.2022", "21.12.2022", 3, 84, 121 },
{ "challah bread", 7, "21.12.2022", "21.12.2022", 21, 26, 131 },
{ "french bread", 10, "21.12.2022", "21.12.2022", 17, 34, 141 },
{ "croissant bread", 12, "21.12.2022", "21.12.2022", 1, 89, 17 },
{ "donut bread", 11, "21.12.2022", "21.12.2022", 22, 77, 9 },
{ "sweet bread", 13, "21.12.2022", "21.12.2022", 11, 44, 65 },
{ "italian bread", 14, "21.12.2022", "21.12.2022", 18, 76, 45 },
{ "russian bread", 16, "21.12.2022", "21.12.2022", 14, 82, 42 },
{ "african bread", 15, "21.12.2022", "21.12.2022", 13, 45, 93 },
{ "japan bread", 7, "21.12.2022", "21.12.2022", 17, 32, 64 },
{ "french bread", 9, "21.12.2022", "21.12.2022", 19, 99, 12 },
{ "belgian bread", 22, "21.12.2022", "21.12.2022", 19, 62, 35 },
{ "british bread", 17, "21.12.2022", "21.12.2022", 16, 53, 48 },
{ "american bread", 14, "21.12.2022", "21.12.2022", 14, 57, 27 },
{ "spanish_breath bread", 18, "21.12.2022", "21.12.2022", 12, 61, 86 },
{ "black bread", 21, "21.12.2022", "21.12.2022", 24, 34, 43 } };
int n=sizeof products/sizeof *products;
sort(products,products+n,[](product a,product b){return a.name < b.name ;});
for(product i:products)cout<<left<<setw(20)<< i.name <<right<<setw(5)
<<i.category<<setw(13)<< i.date <<setw(12)<< i.date _manufacture<<setw(5)
<<i.shelf_life<<setw(5)<<i.price<<setw(5)<<i.count<<endl;}
#include <iomanip>
#include <algorithm>
#include <string>
using namespace std;
int main(){
struct product {
string name; int category; string date; string date_manufacture;
int shelf_life; int price; int count; };
product products[] = {
{ "white bread", 1, "21.12.2022", "21.12.2022", 11, 100, 18 },
{ "wheat bread", 3, "21.12.2022", "21.12.2022", 9, 70, 118 },
{ "rye bread", 4, "21.12.2022", "21.12.2022", 16, 60, 161 },
{ "pretzel bread", 8, "21.12.2022", "21.12.2022", 18, 71, 111 },
{ "pite bread", 6, "21.12.2022", "21.12.2022", 3, 84, 121 },
{ "challah bread", 7, "21.12.2022", "21.12.2022", 21, 26, 131 },
{ "french bread", 10, "21.12.2022", "21.12.2022", 17, 34, 141 },
{ "croissant bread", 12, "21.12.2022", "21.12.2022", 1, 89, 17 },
{ "donut bread", 11, "21.12.2022", "21.12.2022", 22, 77, 9 },
{ "sweet bread", 13, "21.12.2022", "21.12.2022", 11, 44, 65 },
{ "italian bread", 14, "21.12.2022", "21.12.2022", 18, 76, 45 },
{ "russian bread", 16, "21.12.2022", "21.12.2022", 14, 82, 42 },
{ "african bread", 15, "21.12.2022", "21.12.2022", 13, 45, 93 },
{ "japan bread", 7, "21.12.2022", "21.12.2022", 17, 32, 64 },
{ "french bread", 9, "21.12.2022", "21.12.2022", 19, 99, 12 },
{ "belgian bread", 22, "21.12.2022", "21.12.2022", 19, 62, 35 },
{ "british bread", 17, "21.12.2022", "21.12.2022", 16, 53, 48 },
{ "american bread", 14, "21.12.2022", "21.12.2022", 14, 57, 27 },
{ "spanish_breath bread", 18, "21.12.2022", "21.12.2022", 12, 61, 86 },
{ "black bread", 21, "21.12.2022", "21.12.2022", 24, 34, 43 } };
int n=sizeof products/sizeof *products;
sort(products,products+n,[](product a,product b){return a.name < b.name ;});
for(product i:products)cout<<left<<setw(20)<< i.name <<right<<setw(5)
<<i.category<<setw(13)<< i.date <<setw(12)<< i.date _manufacture<<setw(5)
<<i.shelf_life<<setw(5)<<i.price<<setw(5)<<i.count<<endl;}
#include
#include
#include
#include
using namespace std;
struct product {
string name;
int category;
string date;
string date_manufacture;
int shelf_life;
int price;
int count;
};
product products[] = {
{"White bread", 1, "21.12.2022", "21.12.2022", 11, 100, 18},
{"wheat bread", 3, "21.12.2022", "21.12.2022", 9, 70, 118},
{"rye bread", 4, "21.12.2022", "21.12.2022", 16, 60, 161},
{"pretzel bread", 8, "21.12.2022", "21.12.2022", 18, 71, 111},
{" pite bread", 6, "21.12.2022", "21.12.2022", 3, 84, 121},
{"challah bread", 7, "21.12.2022", "21.12.2022", 21, 26, 131},
{"french bread", 10, "21.12.2022", "21.12.2022", 17, 34, 141},
{"croissant bread", 12, "21.12.2022", "21.12.2022", 1, 89, 17},
{"donut bread", 11, "21.12.2022", "21.12.2022", 22, 77, 9},
{"sweet bread", 13, "21.12.2022", "21.12.2022", 11, 44, 65},
{"italian bread", 14, "21.12.2022", "21.12.2022", 18, 76, 45},
{"russian bread", 16, "21.12.2022", "21.12.2022", 14, 82, 42},
{"african bread", 15, "21.12.2022", "21.12.2022", 13, 45, 93},
{"japan bread", 7, "21.12.2022", "21.12.2022", 17, 32, 64},
{"french bread", 9, "21.12.2022", "21.12.2022", 19, 99, 12},
{"belgian bread", 22, "21.12.2022", "21.12.2022", 19, 62, 35},
{"british bread", 17, "21.12.2022", "21.12.2022", 16, 53, 48},
{"american bread", 14, "21.12.2022", "21.12.2022", 14, 57, 27},
{"spanish_breath bread", 18, "21.12.2022", "21.12.2022", 12, 61, 86},
{"black bread", 21, "21.12.2022", "21.12.2022", 24, 34, 43}};
int main() {
auto length = sizeof(products) / sizeof(product);
std::vector v(length);
std::generate(v.begin(), v.end(),
[n = 0]() mutable { return &products[n++]; });
std::sort(v.begin(), v.end(),
[](product *a, product *b) { return a->name < b->name; });
for (const auto i : v) {
cout name
Мага Магеррамов
if (d->strategy != OnManualSubmit)
d->cache.empty();
если переменная стратеги не равна онмануалскрипт то
сбросить кеш
d->cache.empty();
если переменная стратеги не равна онмануалскрипт то
сбросить кеш
Мага Магеррамов
или если -> это указатель то если указатель не на мануал скрипте то сбросить кеш
Похожие вопросы
- Структуры и массивы структур C++
- C++ | Структуры и массивы структур. Помогите пожалуйста!
- C++ | Структуры и массивы структур. Помогите пожалуйста!
- Помогите пожалуйста - создать 4 массива на c++
- Структура и массив структуры С++ Помогите пожалуйста
- Как правильно запихнуть в поле структуры саму структуру? C++
- Нужно решить задачу с массивами на C++
- Написать массив на C(не C++) пожалуйста!!! простым языком с пояснениями
- Помогите плиз написать программу на Си Массив структур
- Массив функции c++ помогите