Неккоректная сортировка и двоичный поиск в массиве структур

Модераторы: Hawk, Romeo, Absurd, DeeJayC, WinMain

Ответить
vistaman1
Сообщения: 1
Зарегистрирован: 28 май 2010, 18:09

Есть такая задача:
Дан список, содержащий 10 записей, каждая из которых имеет структуру:

Шифр товара: тип строка(5 символов)
Наименование товара: тип строка(20 символов)
Цена (грн.): вещественное
Признак наличия или отсутствия: логическое

Список упорядочен по убыванию цены товара.Разработать алгоритмы и программы линейного и двоичного поиска всех товаров, цена которых не превышает 1500 грн., с выводом найденных записей на экран.

В написаной программе не корректно работает сортировка : цена не соответствует товару, и двоичный поиск тоже видно из-за этого тоже не работает должным образом
Вот код программы:

Код: Выделить всё

#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <math.h>

struct shop
{
char code[6];
char name[20];
float price;
bool is;
};


int _tmain(int argc, _TCHAR* argv[])
{
shop a[]={
{"12345","Printer",400,true},
{"54321","holodilnik",5000,true} ,
{"52316","noytbyk",7500,true},
{"15632","tv",8700,true},
{"86423","pilesos",450,true},
{"79563","MFY",1650,true},
{"33256","hlebopesh",1200,true},
{"99854","monitor",1400,true},
{"98648","telefon",500,true},
{"36978","radio",150,true}
};
for(int i=0; i<10; i++) printf("%s %s %f %i\n ", a[i].code, a[i].name, a[i].price, a[i].is);
printf("Seache method #1...\n");
for(int i=0; i<10;i++)
{
if(a[i].price<1500)
{
printf("%s %s %f %i\n ", a[i].code, a[i].name, a[i].price, a[i].is); 
}
}
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 9-i; j++)
{
if(a[j].price>a[j+1].price)
{
float tmp = a[j].price;
a[j].price = a[j+1].price;
a[j+1].price = tmp;
}
}
}
printf("Sort...\n");
for(int i=0; i<10; i++) printf("%s %s %f %i\n ", a[i].code, a[i].name, a[i].price, a[i].is);
printf("Seache method #2...\n");
int k=0,max=0,min=10,b;
do
{
k=(max+min)/2;
if(a[k].price<1500)
min=k;
else
max=k-1;
} while(!(abs(max-min)<=1));
if(a[max].price<1500) b=max;
if(a[min].price<1500) b=min;
for(int i=0; i<b; i++) printf("%s %s %f %i\n ", a[i].code, a[i].name, a[i].price, a[i].is);
while(!_kbhit());
return 0;
}
two0426
Сообщения: 6
Зарегистрирован: 02 июн 2010, 07:30

The fighting time for more than fifteen minutes, actually fifteen minutes Assas has already violent, but because behind there is a ten percent of collective resurrection, therefore, it can more than fifteen minutes, so that staff configuration must consider with adequate supplies for the team Buff include has WOW gold to use. This means that disciplinary Knight, ice method or the survival of hunting these three professions need two members at least to maintain blue huge consumption of the whole team supply.
In addition, we can see that Paragon opener in the
wow power leveling wedding dresses Watches rolex wow gold Louis Vuitton Bags wow power leveling With 25 years wejsklds of experience to draw on, the Warhammer IP is a rich, luscious world full of a wide variety of diverse content. Each race is visually
distinct -- from the lewd and crude Orcs to the proud, lofty High Elves. Even the careers within each race are uniquely different – no one would ever wedding dresses mistake a spanner-totin’ Engineer for an in-your-face Ironbreaker. So, one of the great design challenges in WAR is to provide players with
as much opportunity to customize the look of their characters as possible, while also protecting the silhouette of each race and career. It Watches rolex as much opportunity to customize the look of their characters as possible, while also protecting the silhouette of each race and career. It
a Bright Wizard!Most MMO players understand how armor works visually – when you wear it, it changes the appearance of your avatar. Everyone wow gold loves that moment when you try on some new armor loot for the first time and see how different it makes your character look. That’s cool
in the design process that we were going to do something extra special. We wanted to give players something to aim for, reward players Louis Vuitton Bags for being heroic, hand out great armor, allow you to look different and protect the silhouette all at the same time. How will we do that? WAR
the armor you’re going to wear, you’ve pretty much exhausted all the options for your avatar’s look. The idea behind trophies is to create wow power leveling an additional level of visual customization for your character. For example, let’s say you kill a badass dragon. Some MMOs will make sure the xll
accidental death of four people. From career choices point of view, therefore, can give the second life career is team configuration must be considered.
Second, the basic standards and combination of each occupational profile
You can share two basic data of had killed the Lich King first so that to illustrate the source of our professional standards that set up.
Paragon Association
The total damage amount of one hundred and fifty six million, which play the role of harm in Assas is ninety two point ninety one million on the whole. The team second wound is seventeen thousand, WOW single active DPS is about ten thousand six hundred. The lowest active is eight thousand eight thousand one hundred and eighteen nine DPS, the total fight time is fifteen minutes and eighteen seconds.
The total treatment of five main treatment volume sixty nine point fourteen, the main treatment of the per capita amount is fifteen thousand and sixty four per treatment including over-treatment, the effective treatment of five thousand five hundred and fifty three per second xll
Ответить