Search
 
 
  Engleski
 
 
 
Open in this window (click to change)
Forum@DeGiorgi: Početna
Forum za podršku nastavi na PMF-MO
Login Registracija FAQ Smajlići Članstvo Pretražnik Forum@DeGiorgi: Početna

Sortiranje dvostruko povezne liste(onak hitno) (zadatak)
WWW:

Moja sarma
 
Započnite novu temu   Odgovorite na temu   printer-friendly view    Forum@DeGiorgi: Početna -> Kolegiji 2. godine -> Strukture podataka i algoritmi
Prethodna tema :: Sljedeća tema  
Autor/ica Poruka
stiv66
Forumaš(ica)
Forumaš(ica)


Pridružen/a: 20. 04. 2007. (12:09:27)
Postovi: (1)16
Sarma = la pohva - posuda
= 0 - 0

PostPostano: 12:18 pet, 20. 4. 2007    Naslov: Sortiranje dvostruko povezne liste(onak hitno) Citirajte i odgovorite

Jel bi netko možda zna napisati funkcijicu za uzlazno sortiranje dvostruko povezane liste po ovom red elementu.Ja pokušavam već dva dana i dobio sam fraze.

Progrmćič stvori,obriše i ispiše listu,ali sortirat, ne...
Unaprijed zahvaljujem.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 20


struct cell {
int red;
float clan;

struct cell *next;
struct cell *prev;
};


struct cell *head, *tail;


void stvori(struct cell *cvor)
{
cvor->clan=100* (float)rand()/(RAND_MAX+1);
if(head == NULL) {
head = cvor;
cvor->prev = NULL;
} else {
tail->next = cvor;
cvor->prev = tail;
}

tail = cvor;
cvor->next = NULL;
}


void obrisi(struct cell *cvor) {
if(cvor->prev == NULL)
head = cvor->next;
else
cvor->prev->next = cvor->next;

if(cvor->next == NULL)
tail = cvor->prev;
else
cvor->next->prev = cvor->prev;
}


void ispis(struct cell *cvor)
{
for(cvor=head;cvor!=NULL;cvor=cvor->next)
{
printf("%d,%f\n", cvor->red,cvor->clan);
}
}


int cla(int q[N],int i)
{
int x,y;

y=N* (float)rand()/(RAND_MAX+1);
for(x=0;x<=i;x++)
{
if(y==q[x])
{
y=N* (float)rand()/(RAND_MAX+1);
exit;
}
}
return y;
}




int main(void) {
struct cell *cvor,*novi;
novi=NULL;
int i;
int p[N+1];
p[0]=0;


/* add some numbers to the double linked list */
for(i = 0; i <N; i++) {
cvor = (struct cell *)malloc(sizeof(struct cell));
cvor->red = cla(p,i);
stvori(cvor);
p[i]=cvor->red;
}


ispis(cvor);

/* destroy the dll list */
while(head != NULL)
obrisi(head);obrisi(head);
}
Jel bi netko možda zna napisati funkcijicu za uzlazno sortiranje dvostruko povezane liste po ovom red elementu.Ja pokušavam već dva dana i dobio sam fraze.

Progrmćič stvori,obriše i ispiše listu,ali sortirat, ne...
Unaprijed zahvaljujem.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 20


struct cell {
int red;
float clan;

struct cell *next;
struct cell *prev;
};


struct cell *head, *tail;


void stvori(struct cell *cvor)
{
cvor→clan=100* (float)rand()/(RAND_MAX+1);
if(head == NULL) {
head = cvor;
cvor→prev = NULL;
} else {
tail→next = cvor;
cvor→prev = tail;
}

tail = cvor;
cvor→next = NULL;
}


void obrisi(struct cell *cvor) {
if(cvor→prev == NULL)
head = cvor→next;
else
cvor→prev→next = cvor→next;

if(cvor→next == NULL)
tail = cvor→prev;
else
cvor→next→prev = cvor→prev;
}


void ispis(struct cell *cvor)
{
for(cvor=head;cvor!=NULL;cvor=cvor→next)
{
printf("%d,%f\n", cvor→red,cvor→clan);
}
}


int cla(int q[N],int i)
{
int x,y;

y=N* (float)rand()/(RAND_MAX+1);
for(x=0;x⇐i;x++)
{
if(y==q[x])
{
y=N* (float)rand()/(RAND_MAX+1);
exit;
}
}
return y;
}




int main(void) {
struct cell *cvor,*novi;
novi=NULL;
int i;
int p[N+1];
p[0]=0;


/* add some numbers to the double linked list */
for(i = 0; i <N; i++) {
cvor = (struct cell *)malloc(sizeof(struct cell));
cvor→red = cla(p,i);
stvori(cvor);
p[i]=cvor→red;
}


ispis(cvor);

/* destroy the dll list */
while(head != NULL)
obrisi(head);obrisi(head);
}


[Vrh]
Korisnički profil Pošaljite privatnu poruku
buzov5
Forumaš(ica)
Forumaš(ica)


Pridružen/a: 01. 12. 2006. (13:30:32)
Postovi: (4D)16
Sarma = la pohva - posuda
= 1 - 0
Lokacija: zg

PostPostano: 15:57 sub, 10. 11. 2007    Naslov: Citirajte i odgovorite

ja bi nekako ovako:

void sort(struct cell* prvi, struct cell* zadnji) {
if (prvi==zadnji) return;
struct cell temp, temp2;
for (temp2 = prvi; temp2!= NULL; temp2=temp2->next)
for (temp = prvi; temp->next!= NULL; temp=temp->next)
{
if ((temp->red)>(temp->next->red))
swap (temp, temp->next );
}
temp2 = zadnji->prev;
temp2->next=NULL;
sort (struct cell * prvi, struct cell * temp2);
}

neznam hoce li to radit, al mozda ti pomogne malo
ja bi nekako ovako:

void sort(struct cell* prvi, struct cell* zadnji) {
if (prvi==zadnji) return;
struct cell temp, temp2;
for (temp2 = prvi; temp2!= NULL; temp2=temp2->next)
for (temp = prvi; temp->next!= NULL; temp=temp->next)
{
if ((temp->red)>(temp->next->red))
swap (temp, temp->next );
}
temp2 = zadnji->prev;
temp2->next=NULL;
sort (struct cell * prvi, struct cell * temp2);
}

neznam hoce li to radit, al mozda ti pomogne malo



_________________
tko je ikada naučio od poraza?
[Vrh]
Korisnički profil Pošaljite privatnu poruku
Prethodni postovi:   
Započnite novu temu   Odgovorite na temu   printer-friendly view    Forum@DeGiorgi: Početna -> Kolegiji 2. godine -> Strukture podataka i algoritmi Vremenska zona: GMT + 01:00.
Stranica 1 / 1.

 
Forum(o)Bir:  
Ne možete otvarati nove teme.
Ne možete odgovarati na postove.
Ne možete uređivati Vaše postove.
Ne možete izbrisati Vaše postove.
Ne možete glasovati u anketama.
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2002 phpBB Group
Theme created by Vjacheslav Trushkin
HR (Cro) by Ančica Sečan