找出顺序表中某个数据最大的元素并输出所有最大数据的所有元素信息

8
9787302257646 Data-Structure 35.00
9787302164340 Operating-System 50.00
9787302219972 Software-Engineer 32.00
9787302203513 Database-Principles 36.00
9787810827430 Discrete-Mathematics 36.00
9787302257800 Data-Structure 62.00
9787811234923 Compiler-Principles 62.00
9787822234110 The-C-Programming-Language 38.00
2
Java-Programming-Language
Data-Structure

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define OK 1
#define error 0;
#define MAXSIZE 500

typedef struct
{
	string IBSN;
	string NAME;
	float PRICE;
}Book;

typedef struct
{
	Book* elem;//Book类型的指针
	int length;//顺序表的表长
}List;


int InitList_L(List& L);
int InsertList_L(List& L);
int Re_PrintList_L(List L);
int LocateElem(List L);
int main()
{
	List L;
	InitList_L(L);
	InsertList_L(L);
	/*Re_PrintList_L(L);*/
	LocateElem(L);
	return 0;
}
//初始化链表
int InitList_L(List& L)
{
	L.elem = new Book[MAXSIZE];
	if (!L.elem) exit(0);
	L.length = 0;
	return OK;
}

int InsertList_L(List& L)
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> L.elem[i].IBSN >> L.elem[i].NAME >> L.elem[i].PRICE;
		L.length++;//逆序存储
	}
	return OK;
}

int Re_PrintList_L(List L)
{
	for (int i = 0; i < L.length; i++)
		cout << L.elem[i].IBSN <<" "<< L.elem[i].NAME <<" "<<fixed<<setprecision(2) <<L.elem[i].PRICE << endl;
	return OK;
}

int LocateElem(List L)
{
	float Highest_Price=L.elem[0].PRICE;
	int Num_Highest=0;
	int i = 0;
	for (i = 1; i < L.length-1; i++)
	{
		if (Highest_Price < L.elem[i].PRICE)
			Highest_Price = L.elem[i].PRICE;
	}
	for (i = 1; i < L.length-1; i++)
		if (Highest_Price == L.elem[i].PRICE)
			Num_Highest++;
			cout << Num_Highest<<endl;
			for (i = 1; i < L.length - 1; i++)
				if (Highest_Price == L.elem[i].PRICE)
	cout << L.elem[i].IBSN << " " << L.elem[i].NAME << " " << fixed << setprecision(2) << L.elem[i].PRICE << endl;
	return OK;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值