Untitled

 avatar
unknown
plain_text
6 months ago
4.5 kB
1
Indexable
מחלקה הלקוח המתמיד
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unit4.CollectionsLib;

namespace ConsoleApp8
{
    internal class Customer
    {
        private string name;
        private Node<Flight> flights;
        private int miles;
        public Customer (string name)
        {
            this.name = name;
            flights = null;
            miles = 0;
        }
        public void AddNewFlight (Flight other)
        {
            Node<Flight> p = flights;
            bool IsIn = false;
            while (p != null)
            {
                if (p.GetValue().GetId() == other.GetId())
                {
                    IsIn = true;
                }
                p = p.GetNext();
            }
            if(!IsIn)
            {
                flights= new Node<Flight>(other,flights);
            }
        }
        public int MostPopular()
        {
            int[] arr= new int[50];
            Node<Flight> p= flights;
            while(p != null)
            {
                if(p.GetValue().GetDestination() != 0)
                {
                    arr[p.GetValue().GetDestination()]++;
                }
                p=p.GetNext();
            }
            int max = 0;
            for(int i = 0; i < arr.Length; i++)
            {
                if (arr[i] > max)
                {
                    max = arr[i];
                }
            }
            return max;
        }
        public int SumSameFlight (Customer other)
        {
            Node<Flight> p1= flights;
            Node<Flight> p2= other.flights;
            int count = 0;
            while(p1 != null)
            {
                Node<Flight> p3 = other.flights;
                while( p3 != null)
                {
                    if(p1.GetValue().IsSame(p3.GetValue()))
                    {
                        count++;
                    }
                    p3 = p3.GetNext();
                }
                p1= p1.GetNext();
            }
            return count; 
        }
    }
}
המחלקה - flight
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp8
{
    internal class Flight
    {
        private int id;
        private int origin;
        private int destination;
        private string Fclass;
        private int miles;
        public Flight (int id, int origin, int destination)
        {
            this.id = id;
            this.origin = origin;
            this.destination = destination;
        }
        public int GetId()
        {
            return id;
        }
        public int GetOrigin()
        {
            return origin;
        }
        public int GetDestination()
        {
            return destination;
        }
        public string GetFclass()
        {
            return Fclass;  
        }
        public int GetMiles()
        {
            return miles;
        }
        public bool IsSame (Flight other)
        {
            if (other.origin == origin && other.destination == destination && other.Fclass == Fclass)
            {
                return true;
            }
            return false;
        }

    }
}
פעולות על רשמיה
החוליה האחרונה - פתרון

public static Node<int> EndNode(Node<int> list)

{

Node<int> p = list;

while (p.GetNext()!=null)

p = p.GetNext();

return p;

}
החוליה הקודמת - פתרון

public static Node<int> Prev(Node<int> list, Node<int> p)

{

if (p == list)

return null;

Node<int> prev = list;

while (prev.GetNext() != p)

prev = prev.GetNext();

return prev;

}
פעולות על תור
העתקת תור – פעולה המחזירה תור זהה

public static Queue<int> Clone(Queue<int> q)

{

Queue<int> tmp1 = new Queue<int>();

Queue<int> tmp2 = new Queue<int>();

while (!q.IsEmpty())

{

tmp1.Insert(q.Head());

tmp2.Insert(q.Remove());

}

while (!tmp2.IsEmpty())

{

q.Insert(tmp2.Remove());

}

return tmp1;

}
היפוך תור בעזרת רקורסיה

public static void Reverse(Queue<int> q)

{

if (!q.IsEmpty())

{

int x = q.Remove();

Reverse(q);

q.Insert(x);

}

}
Editor is loading...
Leave a Comment