Очередь с приоритетами - C#
Формулировка задачи:
Использую обычный и отсортированный список.
Подчеркивает в строке L<T> и пишет "Объявление параметра типа должно быть идентификатором, а не типом"
class SortedLinkedList L<T>: LinkedList<T>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Queue
{
public struct L<T>
{
private int key;
private T element;
public T Element { get { return element; } set { element = value; } }
public int Key { get { return key; } set { key = value; } }
}
class SortedLinkedList<L<T>> : LinkedList<T>
where T : IComparable<T>
{
public SortedLinkedList(){}
public void Insert_element(T obj, SortedLinkedList<L<T>> list1)
{
LinkedListNode<L<T>> node = list1.First;
LinkedListNode<T> i;
foreach (T el in list1)
{
if (list1.CompareTo(el) == 1)
{
i = node.Previous;
list1.AddAfter(i, obj);
}
}
}
public int CompareTo(T obj)
{
SortedLinkedList<L<T>> list_o;
LinkedListNode<L<T>> node_o = list_o.First;
if(obj.Key > node_o.Value.Key)
return 1;
else if( obj.Key < node_o.Value.Key)
return -1;
else return 0;
}
}
}Решение задачи: «Очередь с приоритетами»
textual
Листинг программы
public struct L<T> : IComparable<L<T>>
{
public T Element { get; set; }
public int Key { get; set; }
public int CompareTo(L<T> other)
{
return Key.CompareTo(other.Key);
}
}
class SortedLinkedList<T> : LinkedList<L<T>>
{
public void Insert_element(T obj, int key)
{
var newItem = new L<T> {Key = key, Element = obj};
var item = First;
while(item != null)
{
if (item.Value.CompareTo(newItem) > 0)
{
AddBefore(item, newItem);
return;
}
item = item.Next;
}
AddLast(newItem);
}
}