Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Node
- {
- int num;
- Node *link;
- };
- void print(Node *top)
- {
- Node *work = top;
- while (work != NULL)
- {
- cout << work->num << ' ';
- work = work->link;
- }
- cout << endl;
- }
- int numOfElem(Node *top)
- {
- Node *work = top;
- int i = 0;
- while (work != NULL)
- {
- if (work->num != 0 && work->num % 3 == 0)
- i++;
- work = work->link;
- }
- return i;
- }
- int main()
- {
- Node *top = NULL, *work;
- int temp;
- cout << "Input numbers(ctrl+z = exit): ";
- while (cin >> temp)
- {
- work = new Node;
- work->link = top;
- work->num = temp;
- top = work;
- }
- cout << "Numbers: ";
- print(top);
- int elem = numOfElem(top);
- work = new Node;
- work->link = top;
- work->num = elem;
- top = work;
- cout << "New numbers: ";
- print(top);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement