Интерфейсы. Выделить у классов общий интерфейс(или интерфейсы) - C#
Формулировка задачи:
Задание: У классов выделить общий интерфейс ( или интерфейсы ).
первый класс :
второй класс :
Моя попытка по созданию интерфейса :
Не знаю почему, но выдает ошибки вида :
"
_3_8_.ListInt не реализует член интерфейса _3_8_.iExample.DellNth();
_3_8_.ListInt не реализует член интерфейса _3_8_.iExample.Insert();
_3_8_.ListInt не реализует член интерфейса _3_8_.iExample.Push();
_3_8_.ListInt не реализует член интерфейса _3_8_.iExample.PushBack();
_3_8_.ListString не реализует член интерфейса _3_8_.iExample.DellNth();
...
// эти ошибки я понимаю почему выскакивают, но не знаю, как решить это
_3_8_.ListString не реализует член интерфейса "_3_8_.iExample.Pop()". "_3_8_.ListString.Pop()" не удается реализовать "_3_8_.iExample.Pop()", поскольку он не содержит соответствующего типа возвращаемого значения "void".
_3_8_.ListInt не реализует член интерфейса "_3_8_.iExample.PopBack()". "_3_8_.ListInt.PopBack()" не удается реализовать "_3_8_.iExample.PopBack()", поскольку он не содержит соответствующего типа возвращаемого значения "void".
"
Прошу помочь. 3аранее спасибо!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _3_8_
{
class ListInt : iExample
{
Node<int> headNode;
Node<int> tailNode;
//------------------------------------------
protected int lengtch;
public int Count()
{
return lengtch;
}
//-------------------------------------------
public ListInt()
{
this.headNode = null;
this.tailNode = this.headNode;
lengtch = 0;
}
public int this[int index]
{
get
{
Node<int> buf = this.headNode;
for (int i = 0; i < index; i++)
buf = buf.Next;
return buf.Elem;
}
}
public void Push(int Elem) // добавляем в начало
{
if (headNode == null)
{
this.headNode = new Node<int>();
this.headNode.Elem = Elem;
this.tailNode = this.headNode;
this.headNode.NextNode(null);
}
else
{
Node<int> buf = new Node<int>();
buf.NextNode(this.headNode);
this.headNode = buf;
buf.Elem = Elem;
}
this.lengtch++;
}
public void PushBack(int Elem) // добавляем в конец
{
if (headNode == null)
{
this.headNode = new Node<int>();
this.headNode.Elem = Elem;
this.tailNode = this.headNode;
this.headNode.NextNode(null);
}
else
{
Node<int> buf = new Node<int>();
this.tailNode.NextNode(buf);
buf.Elem = Elem;
this.tailNode = buf;
this.tailNode.NextNode(null);
}
++this.lengtch;
}
public void Insert(int n, int Elem) //вставка элемента
{
if (n == 1)
Push(Elem);
else if (n == lengtch + 1)
PushBack(Elem);
else
{
Node<int> buf = this.headNode;
Node<int> tmp = new Node<int>();
if (n <= lengtch)
for (int i = 1; i < n - 1; i++)
buf = buf.Next;
tmp.NextNode(buf.Next);
buf.NextNode(tmp);
tmp.Elem = Elem;
this.lengtch++;
}
}
public int Pop() //Удалить эдемент из начала
{
int result;
result = headNode.Elem;
this.headNode = this.headNode.Next;
this.lengtch--;
return result;
}
public int PopBack() //Удалить эдемент из конца
{
Node<int> lastbutone = LastButOne(this.headNode);
int result = 0;
if (tailNode != null)
{
result = tailNode.Elem;
if (lastbutone != null)
{
this.lengtch--;
lastbutone.NextNode(null);
this.tailNode = lastbutone;
}
}
return result;
}
public int DellNth(int n) //Удалить определенный эедемент
{
if (headNode != null)
{
if (n == 1)
return Pop();
else if (n == lengtch)
return PopBack();
else
{
Node<int> buf = headNode;
for (int i = 1; i < n; i++)
{
buf = buf.Next;
}
buf.NextNode(buf.Next.Next);
this.lengtch--;
return buf.Elem;
}
}
return 0;
}
Node<int> LastButOne(Node<int> head)
{
while((head.Next != this.tailNode) && (head.Next != null))
{
head = head.Next;
}
if (head.Next == null)
return null;
else
return head;
}
}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _3_8_
{
class ListString : iExample
{
Node<string> headNode;
Node<string> tailNode;
//---------------------------------------------
protected int lengtch;
public int Count()
{
return lengtch;
}
//--------------------------------------------
public ListString()
{
this.headNode = null;
this.tailNode = this.headNode;
lengtch = 0;
}
public string this[int index]
{
get
{
Node<string> buf = this.headNode;
for (int i = 0; i < index; i++)
buf = buf.Next;
return buf.Elem;
}
}
public void Push(string Elem) // добавляем в начало
{
if (headNode == null)
{
this.headNode = new Node<string>();
this.headNode.Elem = Elem;
this.tailNode = this.headNode;
this.headNode.NextNode(null);
}
else
{
Node<string> buf = new Node<string>();
buf.NextNode(this.headNode);
this.headNode = buf;
buf.Elem = Elem;
}
this.lengtch++;
}
public void PushBack(string Elem) // добавляем в конец
{
if (headNode == null)
{
this.headNode = new Node<string>();
this.headNode.Elem = Elem;
this.tailNode = this.headNode;
this.headNode.NextNode(null);
}
else
{
Node<string> buf = new Node<string>();
this.tailNode.NextNode(buf);
buf.Elem = Elem;
this.tailNode = buf;
this.tailNode.NextNode(null);
}
this.lengtch++;
}
public void Insert(int n, string Elem) //вставка элемента
{
if (n == 1)
Push(Elem);
else if (n == lengtch + 1)
PushBack(Elem);
else
{
Node<string> buf = this.headNode;
Node<string> tmp = new Node<string>();
if (n <= lengtch)
for (int i = 1; i < n - 1; i++)
buf = buf.Next;
tmp.NextNode(buf.Next);
buf.NextNode(tmp);
tmp.Elem = Elem;
this.lengtch++;
}
}
public string Pop() //Удалить эдемент из начала
{
string result;
result = headNode.Elem;
this.headNode = this.headNode.Next;
lengtch--;
return result;
}
public string PopBack() //Удалить эдемент из конца
{
Node<string> lastbutone = LastButOne(this.headNode);
string result = null;
if (tailNode != null)
{
result = tailNode.Elem;
if (lastbutone != null)
{
this.lengtch--;
lastbutone.NextNode(null);
this.tailNode = lastbutone;
}
}
return result;
}
public string DellNth(int n) //Удалить определенный эедемент
{
if (headNode != null)
{
if (n == 1)
return Pop();
else if (n == lengtch)
return PopBack();
else
{
Node<string> buf = headNode;
for (int i = 1; i < n; i++)
{
buf = buf.Next;
}
buf.NextNode(buf.Next.Next);
this.lengtch--;
return buf.Elem;
}
}
return null;
}
Node<string> LastButOne(Node<string> head)
{
while ((head.Next != this.tailNode) && (head.Next != null))
{
head = head.Next;
}
if (head.Next == null)
return null;
else
return head;
}
}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _3_8_
{
public interface iExample
{
void Push();
void PushBack();
void Insert();
void Pop();
void PopBack();
void DellNth();
}
}Решение задачи: «Интерфейсы. Выделить у классов общий интерфейс(или интерфейсы)»
textual
Листинг программы
class ListString: IMyList<string> { }