Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ExamPreparation2
- {
- class CustomList
- {
- //data – стринг масив
- //count – брой
- //capacity – капацитет
- private List<string> data;
- private int count;
- public CustomList()
- {
- data = new List<string>();
- count = 0;
- }
- public int Count
- {
- get
- {
- return count;
- }
- set
- {
- count = value;
- }
- }
- public void Add(string element)
- {
- data.Add(element);
- }
- public bool Contains(string element)
- {
- return data.Contains(element);
- }
- public bool RemoveByIndex(int index)
- {
- string elementToRemove = data[index];
- return data.Remove(elementToRemove);
- }
- public void ReplaceLastWithFirst()
- {
- // 1,2,3,4 -> 4,2,3,1
- string first = data[0];
- string last = data[data.Count - 1];
- data[0] = last;
- data[data.Count - 1] = first;
- }
- public StringBuilder Info()
- {
- StringBuilder builder = new StringBuilder();
- //CustomList has total count of - 2 and capacity - 2
- builder.Append($"CustomList has total count of - {data.Count}\n");
- foreach(string element in data)
- {
- builder.Append(element + "\n");
- }
- return builder;
- }
- public void Resize()
- {
- count = (count + 1) * 2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement