Guest User

Untitled

a guest
Jan 21st, 2019
1,118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. void maxAndMinElement(){
  2. typedef struct node{
  3. int data;
  4. node *next;
  5. }*nodeptr;
  6. nodeptr arrayLinkList[5], temp, listP;
  7. for(int i = 0; i < 5; i++){
  8. arrayLinkList[i] = new node;
  9. arrayLinkList[i]->data = i+1;
  10. }
  11. for(int i = 0; i < 5; i++)
  12. arrayLinkList[i]->next = arrayLinkList[ i + 1 ];
  13. arrayLinkList[4]->next = 0;
  14. listP = arrayLinkList[0];
  15. temp = listP;
  16. int maxN = arrayLinkList[0]->data, minN = arrayLinkList[0]->data;
  17. while(temp != 0){
  18. if(maxN < temp->data)
  19. maxN = temp->data;
  20. else if( minN > temp->data)
  21. minN = temp->data;
  22. temp = temp->next;
  23. }
  24. std::cout<<"Max NO. => "<<maxN<<" Min NO. => "<<minN;
  25. }
Add Comment
Please, Sign In to add comment