Oct 27th, 2020 (edited)
844
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /*
2.     Задача VII.3:
3.     Да се разработи функция, която намира максималния елемент на линеен
4.     едносвързан списък от цели числа.
5. */
6.
7. #include <iostream>
8. #include <bits/stdc++.h>
9.
10. struct Node
11. {
12.     int data;
13.     struct Node* next;
14. } *first = NULL, *last = NULL;
15. using namespace std;
16.
18. {
19.     if(first == NULL)
20.     {
21.         first = new  Node;
22.         first->data = x;
23.         first->next = NULL;
24.         last = first;
25.     }
26.     else
27.     {
28.         Node *t = new Node;
29.         t->data = x;
30.         t->next = NULL;
31.         last->next = t;
32.         last = t;
33.     }
34. }
35.
36. void displayList(struct Node *p)
37. {
38.     while(p)
39.     {
40.         cout << p->data << " ";
41.         p = p->next;
42.     }
43. }
44. void countNumber(struct Node *p)
45. {
46.     int numberOfElements = 0;
47.     while(p)
48.     {
49.         p = p->next;
50.         numberOfElements++;
51.     }
52.     cout << "The number of elements in the list is: " << numberOfElements << endl;
53. }
54.
55. void countSpecificNumbers(struct Node *p, int specifiedNumber)
56. {
57.     int numberOfElements = 0;
58.     while(p)
59.     {
60.        if(p->data == specifiedNumber)
61.             numberOfElements++;
62.         p = p->next;
63.
64.     }
65.     cout << "The number of elements with value "<< specifiedNumber << " in the list is: " << numberOfElements << endl;
66. }
67.
68. int findMaxList(struct Node*p)
69. {
70.     int maxNumber = INT_MIN;
71.     while(p)
72.     {
73.        if(p->data > maxNumber)
74.             maxNumber = p->data;
75.         p = p->next;
76.
77.     }
78.     cout << "The maximum number is "; // << maxNumber << endl;
79.     return maxNumber;
80. }
81.
82.
83. int main()
84. {