Advertisement
moinularif

DataListController

Oct 14th, 2015
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5.  
  6.  
  7. public class DataRetrive : MonoBehaviour {
  8.  
  9.  
  10.     public List<string> nameOfUniversity = new List<string>();
  11.     public List<int> points = new List<int>();
  12.  
  13.     bool swapped = true;
  14.     void Awake()
  15.     {
  16.         // Read Data from CSV file
  17.         List<Dictionary<string, object>> data = CSVReader.Read("example");
  18.  
  19.         for (var i = 0; i < data.Count; i++)
  20.         {
  21.             // Add data to the list
  22.             nameOfUniversity.Add(data[i]["name"].ToString());
  23.             points.Add((Convert.ToInt32(data[i]["points"].ToString())));
  24.  
  25.                    
  26.         }
  27.        
  28.  
  29.  
  30.     }
  31.  
  32.  
  33.     void Update()
  34.     {
  35.  
  36.         // sorting the list
  37.         while (swapped)
  38.         {
  39.             swapped = false;
  40.             for (int i = 0; i < nameOfUniversity.Count; i++)
  41.             {
  42.                 if (points[i] < points[i + 1])
  43.                 {
  44.                     int tmp = points[i];
  45.                     points[i] = points[i + 1];
  46.                     points[i + 1] = tmp;
  47.  
  48.                     string tmpName = nameOfUniversity[i];
  49.                     nameOfUniversity[i] = nameOfUniversity[i + 1];
  50.                     nameOfUniversity[i + 1] = tmpName;
  51.  
  52.                 }
  53.  
  54.                 swapped = true;
  55.             }
  56.  
  57.             if (!swapped)
  58.                 break;
  59.         }
  60.     }
  61.  
  62.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement