PATbasic1004

来源:互联网 发布:nginx set by lua 编辑:程序博客网 时间:2024/06/13 22:30
#include "stdafx.h"#include<iostream>#include<string>using namespace std;typedef struct node {string name;string number;int result;struct node *next;}NODE;NODE *build(int n) {NODE *head, *p, *nextnode;head = new NODE;head->next = NULL;p = head;for (int i = 0; i < n; i++) {nextnode = new NODE;cin >> nextnode->name;cin >> nextnode->number;cin >> nextnode->result;p->next = nextnode;p = nextnode;}p->next = NULL;return head;}void sort(NODE *head) {NODE *min = head->next, *max = head->next;NODE *p;for (p = head->next->next; p != NULL; p = p->next) {if (p->result > max->result) {max = p;}}for (p = head->next->next; p != NULL; p = p->next) {if (p->result < min->result) {min = p;}}cout << max->name << " " << max->number << endl;cout << min->name << " " << min->number << endl;}int main(){int n;cin >> n;NODE *head = build(n);sort(head);    return 0;}
这题我做麻烦了。。。其实完全用不着链表的,用一个NODE array[]存所有的节点然后排个序OK。万恶的惯性思维。。。
原创粉丝点击