VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: 1 ]
Subject: Re: Quicksort - tengdir listar


Author:
Balli
[ Next Thread | Previous Thread | Next Message | Previous Message ]
Date Posted: 17:35:01 04/28/04 Wed
In reply to: Hjįlmtżr 's message, "Re: Quicksort - tengdir listar" on 13:04:35 04/27/04 Tue

OK, ég hef veriš aš spį mikiš ķ žetta. Hvaš er vitlaust viš žetta hér aš nešan. Eša mundi mašur kanski undir flestum kringumstęšum dęla öllu inn ķ fylki first og žašan aftur inn ķ tengda listan?

kv, Balli

#include
#include
#include
#include
#include


using namespace std;

class node
{
int item;
int count;
public:
node* next;
node* prev;

node(int i, int c)
{
item = i;
count = c;
next = 0;
prev = 0;
}

node(int x, int c, node* p)
{
item = x;
count = c;
prev = p;
}

~node(){}

void setNextNode(node *n)
{
next = n;
}

void setCount(int nr)
{
count = nr;
}


int getCount()
{
return count;
}

int getItem()
{
return item;
}

void inCount()
{
count++;
}

void deCount()
{
count--;
}

bool operator == (node n) const
{
if (count == n.getCount())
return true;
else
return false;
}

bool operator < (node n) const
{
if (count < n.getCount())
return true;
else
return false;
}


};

template
void exch(Item &a, Item &b)
{
int t1 = a->getCount();
int t2 = b->getCount();
a->setCount(t2);
b->setCount(t1);
}

template
void quicksort(Item *first, Item *last)
{
if((first->getItem()) >= (last->getItem()))
return;

Item *Current = last;
Item *Tail = last;
Item *head = first;

for (;;)
{


while (head->getCount() <= Current->getCount())
{
if(head->next == 0)
break;
head = head->next;
}

while ((Current->getCount()) <= (Tail->getCount()))
{

if (Tail->prev == 0)
break;
Tail = Tail->prev;
}

if((head->getItem()) >= (Tail->getItem()))
break;

exch(head, Tail);
}

if((head->prev) == 0)
return;

if((Tail->next) == 0)
return;

exch(head, Tail);

quicksort(first, head->prev);
quicksort(Tail->next, last);
}



int main()
{
node *nNode = new node(1, 100);
node *tNode;

for(int i = 0;i < 9; i++)
{
int iTala = rand() % 1000;

tNode = nNode;

nNode = new node(i + 2, iTala, tNode);
tNode->setNextNode(nNode);

}

tNode = nNode;

for(int i = 0;i < 9; i++)
{
cout << nNode->getCount() << "nr. " << nNode->getItem() << endl;
nNode = nNode->prev;
}

cout << nNode->getCount() << "nr. " << nNode->getItem() <
quicksort(nNode, tNode);
cout << "Eftir Quicksort" << endl;
for(int i = 0;i < 10; i++)
{
cout << nNode->getCount() << " nr. " << nNode->getItem() << endl;
nNode = nNode->next;
}

char stop;
cin >> stop;


return 0;
}

[ Next Thread | Previous Thread | Next Message | Previous Message ]

Replies:
Subject Author Date
Re: Quicksort - tengdir listarHjįlmtżr00:31:54 04/29/04 Thu
Re: Quicksort - tengdir listarAndreas Gušmundsson20:15:32 04/29/04 Thu


Post a message:
This forum requires an account to post.
[ Create Account ]
[ Login ]
[ Contact Forum Admin ]


Forum timezone: GMT+0
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.