link list?
pls explane me
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <iostream>
using namespace std;
struct Node{
int data;
Node *pNext;
};
struct List{
Node *pHead;
Node *pTail;
};
void Init(List &l){
l.pHead = l.pTail = NULL;
}
Node* GetNode(int x){
Node *p = new Node;
if(p == NULL)
return NULL;
p ->data = x;
p ->pNext = NULL;
return p;
}
void AddTail( List &l, Node *p){
if( l.pHead == NULL){
l.pHead = l.pTail = p;
}else{
l.pTail ->pNext = p;
l.pTail = p;
}
}
void input(List &l){
int n;
cout << "Nhap so Node : ";
cin >> n;
Init(l);
for(int i = 0; i < n; i++){
int x;
cin >> x;
Node *p = GetNode(x);
AddTail(l, p);
}
}
void timMax(List l){
int x = l.pHead ->data ;
for(Node *p = l.pHead; p != NULL; p = p ->pNext){
if( p ->data > x)
x = p ->data;
}
cout << "\nMax : " << x;
}
int main(){
List l;
input(l);
timMax(l);
return 0;
}
|
Topic archived. No new replies allowed.