Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //clsarraylist
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace conArrayList
- {
- class ArrayList:IList
- {
- protected int size;
- protected int current;
- protected int head;
- protected int tail;
- protected object[] array;
- //private object first, last;
- private int count;
- public object Last
- {
- get
- {
- try
- {
- return array[tail-1];
- }
- catch (IndexOutOfRangeException)
- {
- Console.WriteLine("List is empty!");
- return -32767;
- }
- }
- }
- public ArrayList(int size)
- {
- this.size = size;
- array = new object[size];
- head = -1;
- tail = 0;
- current = 0;
- Count = 0;
- }
- public bool IsEmpty()
- {
- return(Count==0);
- }
- public bool IsFull()
- {
- return (Count == size);
- }
- public void Clear()
- {
- this.head = -1;
- tail = 0;
- current = 0;
- this.Count = 0;
- GC.Collect();
- GC.WaitForPendingFinalizers();
- }
- public void Insert(object item)
- {
- if (!IsFull())
- {
- if (head == -1)//empty
- {
- head=head+1;
- array[head] = item;
- }
- else
- {
- tail = tail + 1;
- array[tail] = item;
- }
- Count++;
- }
- else
- {
- Console.WriteLine("List is full");
- }
- }
- public object First
- {
- get
- {
- try
- {
- return array[head];
- }
- catch (IndexOutOfRangeException)
- {
- Console.WriteLine("List is empty!");
- return -32767;
- }
- }
- }
- public int Count
- {
- get { return count; }
- set { count = value; }
- }
- public void DisplayList()
- {
- foreach (object val in array)
- {
- Console.Write(val+" ");
- }
- }
- }
- }
- //clsilist
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace conArrayList
- {
- interface IList
- {
- int Count
- {
- set;
- get;
- }
- object First
- {
- get;
- }
- object Last
- {
- get;
- }
- bool IsEmpty();
- void Insert(object item);
- void DisplayList();
- //bool Find(object item);
- //void Remove(object item);
- //void InsertAt(object item, int index);
- void Clear();
- }
- }
- //nodelist
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace conArrayList
- {
- public class Node
- {
- private object data;
- private Node next;
- public Node(object item, Node n)
- {
- this.Data= item;
- this.Next= n;
- }
- public object Data
- {
- get { return data; }
- set { data = value; }
- }
- internal Node Next
- {
- get { return next; }
- set { next = value; }
- }
- }
- }
- //program
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace conArrayList
- {
- class Program
- {
- static void Main(string[] args)
- {
- ArrayList list = new ArrayList(4);
- list.Insert(10);
- list.Insert(20);
- list.Insert(30);
- list.DisplayList();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement