Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Assignment
- {
- class Program
- {
- static void Main(string[] args)
- {
- Stack stk = new Stack();
- stk.Pop();
- stk.Peek();
- stk.PrintStack();
- for (int i = 0; i < stk.GetCustomer().Length; i++)
- {
- Customer c = new Customer();
- stk.Push(c);
- }
- stk.PrintStack();
- Customer t = new Customer();
- stk.Push(t);
- for (int i = 0; i < 4; i++)
- stk.Pop();
- Console.WriteLine("Peek");
- stk.Peek();
- stk.Pop();
- stk.Peek();
- }
- }
- }
- -------------------------------------------------------------------------------------
- using System;
- namespace Assignment
- {
- class Customer
- {
- private string FirstName, LastName;
- public Customer()
- {
- Console.Write("Enter first name: ");
- FirstName = Console.ReadLine();
- Console.Write("Enter surname: ");
- LastName = Console.ReadLine();
- }
- public void SetFirstName(string firstName) { this.FirstName = firstName; }
- public void SetLastName(string lastName) { this.LastName = lastName; }
- public string GetFirstName() { return FirstName; }
- public string GetLastName() { return LastName; }
- public void PrintCustomer(int index)
- {
- Console.WriteLine($"Customer {index}: {FirstName} {LastName}");
- }
- }
- }
- --------------------------------------------------------------------------------------
- using System;
- namespace Assignment
- {
- class Stack
- {
- private int pointer;
- private Customer[] customers;
- public Stack()
- {
- Console.Write("Enter clients amount: ");
- int cAm = int.Parse(Console.ReadLine());
- customers = new Customer[cAm];
- pointer = 0;
- }
- public void SetPointer(int pointer) { this.pointer = pointer; }
- public Customer[] GetCustomer() { return customers; }
- public int GetPointer() { return pointer; }
- public bool IsFull()
- {
- if (pointer >= customers.Length) return true;
- else return false;
- }
- public bool IsEmpty()
- {
- if (pointer == 0) return true;
- else return false;
- }
- public void Push(Customer c)
- {
- if (IsEmpty() == true)
- Console.WriteLine("Can't push, no place.");
- else
- {
- customers[pointer] = c;
- pointer++;
- }
- }
- public Customer Pop()
- {
- if (IsEmpty() == true)
- {
- Console.WriteLine("Stack's empty.");
- return null;
- }
- else
- {
- Console.Write("Popping > ");
- customers[pointer - 1].PrintCustomer(pointer - 1);
- customers[pointer - 1].SetFirstName("");
- customers[pointer - 1].SetLastName("");
- pointer--;
- return null;
- }
- }
- public Customer Peek()
- {
- if (IsEmpty()==true)
- {
- Console.WriteLine("Stack's empty.");
- return null;
- }
- Console.WriteLine($"Last Customer: ");
- customers[pointer - 1].PrintCustomer(pointer - 1);
- return null;
- }
- public void PrintStack()
- {
- if (IsEmpty() == true)
- Console.WriteLine("Stack's empty.");
- else
- {
- for (int i = 0; i < pointer; i++)
- {
- customers[i].PrintCustomer(i);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement