61 lines
1.3 KiB
C++
61 lines
1.3 KiB
C++
#include <iostream>
|
|
#include <iomanip>
|
|
using namespace std;
|
|
struct LinkNode{
|
|
double data;
|
|
LinkNode* next;
|
|
};
|
|
void swap(double &a, double &b){
|
|
double tmp = a;
|
|
a = b;
|
|
b = tmp;
|
|
}
|
|
LinkNode* GetPartion(LinkNode* pBegin, LinkNode* pEnd)
|
|
{
|
|
double key = pBegin->data;
|
|
LinkNode* p = pBegin;
|
|
LinkNode* q = p->next;
|
|
|
|
while(q != pEnd)
|
|
{
|
|
if(q->data < key)
|
|
{
|
|
p = p->next;
|
|
swap(p->data,q->data);
|
|
}
|
|
q = q->next;
|
|
}
|
|
swap(p->data,pBegin->data);
|
|
return p;
|
|
}
|
|
void QuickSort(LinkNode* pBeign, LinkNode* pEnd, LinkNode* in)
|
|
{
|
|
if(pBeign != pEnd)
|
|
{
|
|
LinkNode* partion = GetPartion(pBeign,pEnd);
|
|
QuickSort(pBeign,partion,in);
|
|
QuickSort(partion->next,pEnd,in);
|
|
}
|
|
}
|
|
void QuickSort(LinkNode* in){
|
|
QuickSort(in, nullptr,in);
|
|
}
|
|
int main(){
|
|
int n;
|
|
double t;
|
|
while (cin >> n){
|
|
LinkNode *head = nullptr;
|
|
for(int i = 0;i<n;i++){
|
|
cin >> t;
|
|
head = new LinkNode{t,head};
|
|
}
|
|
QuickSort(head = new LinkNode{0,head});
|
|
head = head->next->next;
|
|
t = 0;
|
|
while (head->next){
|
|
t += head->data;
|
|
head = head->next;
|
|
}
|
|
cout << setiosflags(ios::fixed) << setprecision(2) << t/(n-2)<< endl;
|
|
}
|
|
} |