Moc prosím jestli by mi nemohl někdo pomoct s vytvořením funkce na vyhledání největšího nebo nejmenšího prvku v seznamu.
#include <cstdlib>
#include <iostream>
using namespace std;
class List{
private:
typedef struct node{
int data;
node* next;
}* nodePtr;
nodePtr head;
nodePtr curr;
nodePtr temp;
public:
List();
void AddNode(int addData);
void DeleteNode(int delData);
void PrintList();
};
List::List(){
head = NULL;
curr = NULL;
temp = NULL;
}
void List::AddNode(int addData){
nodePtr n = new node;
n->next = NULL;
n->data = addData;
if(head != NULL){
curr = head;
while(curr->next != NULL){
curr = curr->next;
}
curr->next = n;
}
else{
head = n;
}
}
void List::DeleteNode(int delData){
nodePtr delPtr = NULL;
temp = head;
curr = head;
while(curr != NULL && curr->data != delData){
temp = curr;
curr = curr->next;
}
if(curr == NULL){
cout << "Nelze smazat hodnotu " << delData << ", neni v seznamu.\n";
delete delPtr;
}
else{
delPtr = curr;
curr = curr->next;
temp->next = curr;
if(delPtr == head){
head = head->next;
temp = NULL;
}
delete delPtr;
cout << "Hodnota " << delData << " byla smazana.\n";
}
}
void List::PrintList(){
curr = head;
while(curr != NULL)
{
cout << curr->data << endl;
curr = curr->next;
}
}
int main(){
List First;
First.AddNode(1);
First.AddNode(2);
First.AddNode(3);
First.AddNode(4);
First.AddNode(5);
First.PrintList();
First.DeleteNode(3);
First.DeleteNode(5);
First.PrintList();
First.DeleteNode(8);
First.PrintList();
First.DeleteNode(1);
First.PrintList();
system("pause");
}