Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Lab4
- {
- class Stack
- {
- public string name; // Прізвище працівника
- public int salary; // Оклад
- public Stack next;
- }
- class Program
- {
- static void Main()
- {
- Stack head = null;
- Stack current = null;
- Console.WriteLine("Ви бажаєте створити стек (y-так)");
- string n = Console.ReadLine();
- int count = 0;
- //Створення стеку
- while (n == "y")
- {
- current = new Stack();
- Console.WriteLine("ВВедiть значення:");
- Console.WriteLine("Прiзвище працiвника: ");
- current.name = Console.ReadLine();
- Console.WriteLine("Оклад: ");
- current.salary = Convert.ToInt32(Console.ReadLine());
- current.next = head;
- head = current;
- count++;
- Console.WriteLine("Ви бажаєте продовжити введення елементiв (y-так)");
- n = Console.ReadLine();
- }
- Console.WriteLine("Кiлькiсть елементiв в стеку: {0}", count);
- //Перегляд вмісту стеку
- //Стек не знищується
- current = head;
- while (current != null)
- {
- Console.WriteLine($"Прiзвище: {current.name} Оклад: {current.salary}");
- current = current.next;
- }
- //Додавання елемента в стек
- current = new Stack();
- Console.WriteLine("ВВедiть значення:");
- Console.WriteLine("Прiзвище працiвника: ");
- current.name = Console.ReadLine();
- Console.WriteLine("Оклад: ");
- current.salary = Convert.ToInt32(Console.ReadLine());
- current.next = head;
- head = current;
- count++;
- Console.WriteLine("Кiлькiсть елементiв в стеку: {0}", count);
- current = head;
- while (current != null)
- {
- Console.WriteLine($"Прiзвище: {current.name} Оклад: {current.salary}");
- current = current.next;
- current = current.next;
- }
- int sum = 0;
- int N = 0;
- while (current != null)
- {
- sum += current.salary;
- N++;
- current = current.next;
- }
- Console.WriteLine("The sum of all the elements in the stack : {0}", sum );
- int average = sum / N;
- Console.WriteLine("Arithmetic mean : {0}", average);
- Console.WriteLine("\nСтек знищено");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment