Надо удалить наибольший элемент из первых n-элементов списка. Как-то не соображу как это сделать. Подскажите, пожалуйста, как это сделать.
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
using namespace std;
#define List struct list
List
{
int Dn;
List* Nx;
};
class cList
{
protected:
List* p;
public:
cList() : p(NULL) {}
~cList();
int Empty() { return p == NULL; }
void AddHead(int D)
{
List* q = new(List);
q->Dn = D;
q->Nx = p;
p = q;
}
void Display();
void AddEnd(int D);
long Len();
void DelFirst()
{
List* q = p;
p = p->Nx;
delete(q);
}
};
void cList::Display()
{
List* t = p;
if (p)
while (t)
{
cout << t->Dn << " ";
t = t->Nx;
}
else cout << "->|";
cout << endl;
};
void cList::AddEnd(int D)
{
List* q = new List;
q->Dn = D;
q->Nx = NULL;
List* t = p;
if (p)
{
while (t->Nx) t = t->Nx;
t->Nx = q;
}
else p = q;
};
long cList::Len()
{
if (p)
{
List* t = p;
long i = 0;
while (t)
{
t = t->Nx;
i++;
};
return i;
};
return 0;
};
cList::~cList()
{
while (!Empty()) DelFirst();
};
int main()
{
cout << "Demo List" << endl;
int A[12] = {23, 19, 14, 43, 17, 22, -31, 46, -7, 2, 64, 53};
cList L1;
cout << "The list is empty?:" << L1.Empty() << endl;
L1.Display();
cout << endl;
for (int i = 0; i < 12; i++) L1.AddEnd(A[i]);
L1.Display();
cout << endl;
cout << "Count Element = " << L1.Len() << endl;
L1.~cList();
system("pause");
return 0;
}