could i ever make this code right or is it totally wrong, here is code:
List listaIntegera = new List();
listaIntegera.InsertFront(67);
listaIntegera.InsertFront(1);
listaIntegera.InsertFront(4);
listaIntegera.InsertFront(23);
listaIntegera.InsertFront(9);
listaIntegera.InsertFront(12);
listaIntegera.InsertFront(27);
listaIntegera.Display();
object prviElement = listaIntegera.GetFirst(listaIntegera);
Node prvi = new Node(0, null);
prvi = prviElement as Node;
Console.WriteLine("........................");
Console.WriteLine("prvi element je " + prviElement);
object zadnjiElement = listaIntegera.GetLast(listaIntegera);
Node zadnji = zadnjiElement as Node;
Console.WriteLine("........................");
Console.WriteLine("zadnji element je "+ zadnji);
Console.WriteLine("........................");
Quick.Partition(listaIntegera, prviElement, zadnjiElement);
listaIntegera.Display();
Quick.Sort(listaIntegera, prviElement, zadnjiElement);
listaIntegera.Display();
class List
{
private Node head;
private Node tail;
public List() { head = tail = null; }
public void InsertFront(int data)
{
if (IsEmpty())
head = tail = new Node(data, null);
else
head = new Node(data, head);
}
public bool IsEmpty() { return head == null; }
public void Display()
{
Node current = head;
while (current != null)
{
Console.WriteLine(current.Element + " ");
current = current.Next;
}
Console.WriteLine();
}
public object GetFirst(object data)
{
if (IsEmpty())
return 0;
object obj = null;
obj = head.Element;
return obj;
}
public object GetLast(object data)
{
if (IsEmpty())
return 0;
object obj = null;
obj = tail.Element;
return obj;
}
public object Sljedeci(object data)
{
Node trenutni = data as Node;
Node sljedeci = new Node(trenutni.Element, trenutni.Next);
return sljedeci;
}
public object Prethodni(object data, object lista)
{
Node trenutni = data as Node;
List Lista = lista as List;
object prviUlisti = Lista.GetFirst(lista);
Node current = prviUlisti as Node;
if (current.Next == trenutni)
return current;
while (current.Next != trenutni)
current = current.Next;
return current;
}
class Quick
{
public static int Partition(object lista,
object left, object right)
{
Node Pivot = left as Node;
Node Right = right as Node;
if (Pivot == null)
return 0;
Node pivot = new Node(Pivot.Element, Pivot.Next);
// object pivot = left;
// Node Pivot = pivot as Node;
if (pivot.Next == null)
return 0;
if (pivot.Element == 0)
return 0;
//int last = left;
Node i = pivot.Next;
while (i != Right)
i = i.Next;
if (i.Element >= pivot.Element)
Swap(lista, pivot.Next, i);
Swap(lista, pivot, pivot.Next);
return pivot.Element;
}
public static void Swap(object lista, object first, object second)
{
Node prvi = first as Node;
Node drugi = second as Node;
Node temp = prvi.Next;
prvi.Next = drugi.Next;
drugi.Next = temp;
}
public static void Sort(object lista, object left, object right)
{
Node Left = left as Node;
Node Right = right as Node;
List Lista = lista as List;
if (Left == null)
return;
if (Right == null)
return;
if (Left.Element >= Right.Element) return;
int last = Partition(lista, Left, Right);
Sort(lista, Left, Lista.Prethodni(Left, lista));
Sort(lista, Lista.Sljedeci(Left), right);
}
}
}
Edited by macosxnerd101: Post your code BETWEEN your code tags. Like so:

New Topic/Question
Reply




MultiQuote




|