Example #1
0
        public List <Airbnb> GetDataFromFile()
        {
            List <Airbnb> collection = new List <Airbnb>();
            StreamReader  reader     = new StreamReader(@"dados_airbnb.txt");

            reader.ReadLine();

            while (!reader.EndOfStream)
            {
                string[] values = reader.ReadLine().Split('\t');

                Airbnb row = new Airbnb();
                row.roomID              = int.Parse(values[0]);
                row.hostID              = int.Parse(values[1]);
                row.roomType            = values[2];
                row.contry              = values[3];
                row.city                = values[4];
                row.neighborhood        = values[5];
                row.reviews             = int.Parse(values[6]);
                row.overallSatisfaction = float.Parse(values[7]);
                row.accommodates        = int.Parse(values[8]);
                row.bedrooms            = float.Parse(values[9]);
                row.price               = double.Parse(values[10]);
                row.propertyType        = values[11];

                collection.Add(row);
            }

            reader.Close();
            return(collection);
        }
Example #2
0
        public static void Mixed(List <Airbnb> l)
        {
            int           half = l.Count / 2 + l.Count % 2;
            List <Airbnb> l1   = l.GetRange(0, half);
            List <Airbnb> l2   = l.GetRange(half, l.Count / 2);

            for (int i = 0; i < l1.Count - 1; i++)
            {
                for (int j = 0; j < l1.Count - i - 1; j++)
                {
                    if (l1[j].roomID > l1[j + 1].roomID)
                    {
                        Airbnb aux = l1[j];
                        l1[j]     = l1[j + 1];
                        l1[j + 1] = aux;
                    }
                }
            }

            for (int i = 0; i < l2.Count - 1; i++)
            {
                int min = i;
                for (int j = i + 1; j < l2.Count; j++)
                {
                    if (l2[j].roomID < l2[min].roomID)
                    {
                        min = j;
                    }
                }

                Airbnb aux = l2[i];
                l2[i]   = l2[min];
                l2[min] = aux;
            }

            l1.Add(new Airbnb()
            {
                roomID = Int32.MaxValue
            });
            l2.Add(new Airbnb()
            {
                roomID = Int32.MaxValue
            });

            int i1 = 0, i2 = 0;

            for (int k = 0; k <= l.Count - 1; k++)
            {
                if (l1[i1].roomID <= l2[i2].roomID)
                {
                    l[k] = l1[i1++];
                }
                else
                {
                    l[k] = l2[i2++];
                }
            }
        }
Example #3
0
 public static void Insertion(List <Airbnb> l)
 {
     for (int i = 1; i < l.Count; i++)
     {
         int j = i;
         while (j > 0 && l[j].roomID < l[j - 1].roomID)
         {
             Airbnb aux = l[j];
             l[j]     = l[j - 1];
             l[j - 1] = aux;
             j--;
         }
     }
 }
Example #4
0
 public static void Bubble(List <Airbnb> l)
 {
     for (int i = 0; i < l.Count - 1; i++)
     {
         for (int j = 0; j < l.Count - i - 1; j++)
         {
             if (l[j].roomID > l[j + 1].roomID)
             {
                 Airbnb aux = l[j];
                 l[j]     = l[j + 1];
                 l[j + 1] = aux;
             }
         }
     }
 }
        static void Main(string[] args)
        {
            Console.WriteLine("Sorting Algorithms Analysis\n");

            Console.Write("Which case? (b/r/w): ");
            char sortCase = char.Parse(Console.ReadLine());


            Airbnb        airbnb   = new Airbnb();
            List <Airbnb> roomList = airbnb.GetDataFromFile();
            List <Result> results  = new List <Result>();

            if (sortCase == 'b' || sortCase == 'w')
            {
                roomList = roomList.OrderBy(o => o.roomID).ToList();
                if (sortCase == 'w')
                {
                    roomList.Reverse();
                }
            }

            for (int i = 2000; i <= 128000; i *= 2)
            {
                for (int j = 1; j <= 5; j++)
                {
                    results.Add(new Result()
                    {
                        attempt = j, sample = i
                    });
                    foreach (string type in types)
                    {
                        long time = airbnb.SortList(roomList, i, type);
                        results[results.Count - 1].GetType().GetProperty(type).SetValue(results[results.Count - 1], time);

                        Console.WriteLine("Attempt: {0}", j);
                        Console.WriteLine("Sample.: {0}", i);
                        Console.WriteLine("Type...: {0}", type);
                        Console.WriteLine("Time...: {0}\n", time);
                    }
                }
            }

            airbnb.WriteResultsToFile(results);
            Console.WriteLine("Done! Check out the results in the csv generated file.");
        }
Example #6
0
        public static void Selection(List <Airbnb> l)
        {
            for (int i = 0; i < l.Count - 1; i++)
            {
                int min = i;

                for (int j = i + 1; j < l.Count; j++)
                {
                    if (l[j].roomID < l[min].roomID)
                    {
                        min = j;
                    }
                }

                Airbnb aux = l[i];
                l[i]   = l[min];
                l[min] = aux;
            }
        }
Example #7
0
        public static void Quick(List <Airbnb> l, int left, int right)
        {
            int i     = left,
                j     = right,
                pivot = l[(left + right) / 2].roomID;

            while (i <= j)
            {
                while (l[i].roomID < pivot && i < right)
                {
                    i++;
                }
                while (l[j].roomID > pivot && j > left)
                {
                    j--;
                }

                if (i <= j)
                {
                    Airbnb aux = l[i];
                    l[i] = l[j];
                    l[j] = aux;
                    i++;
                    j--;
                }
            }

            if (j > left)
            {
                Quick(l, left, j);
            }

            if (i < right)
            {
                Quick(l, i, right);
            }
        }