Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LinearArrayList
- {
- private int size;
- private int[] values;
- public LinearArrayList(int capacity)
- {
- values = new int[capacity];
- size = values.Length;
- values[0] = 35;
- values[1] = 24;
- values[2] = 45;
- values[3] = 16;
- values[4] = 6;
- }
- public void display()
- {
- foreach (int i in values)
- {
- Console.WriteLine(i);
- }
- Console.ReadLine();
- }
- public void destroy()
- {
- Array.Clear(values, 0, values.Length);
- }
- public bool isEmpty()
- {
- if (size == 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public bool isFull()
- {
- if (values.Length == 4)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public void addFirst(int value)
- {
- if (isFull() == true)
- {
- throw new Exception("List is Full");
- }
- else
- {
- for (int i = size; i > 0; i--)
- {
- values[i] = values[i - 1];
- }
- values[0] = value;
- size++;
- }
- }
- public void addLast(int value)
- {
- if (isFull() == true)
- {
- throw new Exception("List is Full");
- }
- else
- {
- for (int i = size; i > 0; i++)
- {
- values[i] = values[i + 1];
- }
- values[0] = value;
- size++;
- }
- }
- public void sort()
- {
- int i, j;
- int min, temp;
- for (i = 0; i < size - 1; i++)
- {
- min = i;
- for (j = i + 1; j < size; j++)
- {
- if (values[j] < values[min])
- {
- min = j;
- }
- }
- temp = values[i];
- values[i] = values[min];
- values[min] = temp;
Add Comment
Please, Sign In to add comment