Kod: |
void MAKE_NULL (DICTIONARY *A){
int i; for (i=0; i<B; i++) (*A)[i] = NULL; } int MEMBER(char x[], DICTIONARY A){ celltype *current; current = A[h(x)]; while (current != NULL){ if (strcmp(current->element, x)==0) return 1; else current = current->next; } return 0; } void INSERT(char x[], DICTIONARY *A){ celltype *temp; temp = (*A)[h(x)]; (*A)[h(x)] = (celltype*)malloc(sizeof(celltype)); strcpy((*A)[h(x)]->element, x); (*A)[h(x)]->next = temp; return; } void DELETE(char x[], DICTIONARY *A){ celltype *current, *temp; if ( (*A)[h(x)] != NULL) { if (strcmp((*A)[h(x)]->element,x)==0) { temp = (*A)[h(x)]; (*A)[h(x)] = (*A)[h(x)]->next; free(temp); }else{ current = (*A)[h(x)]; while (current->next != NULL) if (strcmp(current->next->element, x)==0) { temp = current->next; current->next = current->next->next; free(temp); return; }else current = current->next; } } } |
Buki (napisa): | ||
imam u zadatku implementaciju rjecnika preko otvorene hash tablice i sad kad sam to napisala, build log mi ne javlja nikakve greske niti upozorenja, ali program prestane raditi cim ga pokrenem, prije ikakvog unosa pa molim ako netko vidi u cemu je problem da se javi
ovo je kod:
|
Kod: |
void MAKE_NULL (DICTIONARY *A){
int i; for (i=0; i<B; i++){ (*A)[i] = (celltype*)malloc(sizeof(celltype)); (*A)[i] = NULL; } return; } |
Kod: |
int main (void){
DICTIONARY A; char naredba[30], rijec[30]; MAKE_NULL(&A); INSERT("auto", &A); INSERT("break", &A); INSERT("case", &A); INSERT("char", &A); INSERT("const", &A); |
Buki (napisa): | ||||
aha, kuzim otprilike, sad sam izmjenila make_null da mi izgleda ovako
i sad mi se vise ne rusi kad ga pokrenem vec se jednostavno nista ne dogada, a mogu pisat normalno u onom crnom prozoru ovo mi je prvi dio main-a, dalje je sve vezano za konkretan zadatak:
EDIT: puno ti hvala, sad mi radi normalno, ali samo ako mi je B<5, imas ideju kako da to ispravim? |
Kod: |
typedef struct { int last; elementtype labels[MAXLENGHT]; } HEAP; elementtype DELETE_MAX (HEAP *H) { int i, j; elementtype max; if (H->last < 0) { error("Hrpa je prazna!"); } else { max = H->labels[0]; //u korijenu je najveci element H->labels[0] = H->labels[H->last]; (H->last)--; i = 0; while (i <= (H->last+1)/2-1) { if ((2*i + 1 == H->last) || (H->labels[2*i + 1] > H->labels[2*i + 2])) j = 2*i + 1; else j = 2*i + 2; if (H->labels[i] < H->labels[j]) { swap(H->labels[i], H->labels[j]); i = j; } else return max; } return max; } } |
michelangelo (napisa): |
može neko pojašnjenje ovako zadane strukture nisam sigurna s čime tu zapravo raspolažem... ovaj labels mi nije jasan, što mi tu zapravo ulazi???
Neka je uredjeno stablo prikazano pomoću slijedeće strukture podataka: typedef struct { LIST header[maxnodes] ; labeltype labels[maxnodes] ; node root; } TREE; Uz ovakvu reprezentaciju implementirajte a.t.p. TREE. Pretpostavljamo da je node tipa int, labeltype je podatak tipa char, dok je a.t.p. LIST implementiran pomoću pointera, a header[i] predstavlja listu djece čvora i. |
mini (napisa): | ||
trebalo bi i meni par odgovora. kako uopće implementirati listu. može li mi netko dati primjer za bar jednu funkciju? malo me to sve skupa zbunilo |
Kod: |
typedef struct tag_celltype
{ struct tag_celltype *next; node childIndex; } celltype; |
Kod: |
typedef struct cell_tag {
char element[100]; struct cell_tag *next; } celltype; typedef celltype *SET; void MAKE_NULL(SET *A){ *A = (celltype*) malloc(sizeof(celltype)); (*A)->next = NULL; } void INSERT(char x[], SET *A){ celltype *novi, *prethodni, *trenutni; prethodni = *A; trenutni = prethodni->next; while(trenutni != NULL && strcmp(trenutni->element,x)<0){ prethodni = trenutni; trenutni = prethodni->next; } if (trenutni != NULL && strcmp(trenutni->element,x)==0) return; else{ novi = (celltype*) malloc(sizeof(celltype)); strcpy(novi->element,x); novi->next=trenutni; prethodni->next = novi; } } |
pajopatak (napisa): | ||
može mala pomoć,imam implementaciju SET-a pomoću vezane liste, to sam sve napravila i sad kao zadani elementtype mi je char i to nikako nemogu ukomponirat u f-je,stalno mi grešku javlja,evo samo dio koda, pa ako netko zna u čemu je problem:
|
Kod: |
#include<stdio.h>
#include<stdlib.h> #include<string.h> |
Kod: |
void INSERT(char x, BTREE *T)
{ int i; if (T->labels[0] == PRAZNO) { T->labels[0] = x; return; } else if (x < T->labels[0]) { i = 1; while(1) { if (T->labels[i] == PRAZNO) { T->labels[i] = x; break; } else if (x < T->labels[i]) i = 2*i+1; else if (x > T->labels[i]) i = 2*i+2; } return; } else if(x > T->labels[0]) { i = 2; while(1) { if (T->labels[i] == PRAZNO) { T->labels[i] = x; break; } else if (x < T->labels[i]) i = 2*i+1; else if (x > T->labels[i]) i = 2*i+2; } return; } } |
pupi (napisa): | ||
Zadatak glasi ovako :
Sortirajte zadanu listu pomoću binarnog stabla traženja uzlazno i silazno koristeći isto binarno stablo traženja. Pretpostavimo da lista sadrži elemente tipa char. Binarno stablo traženja je prikazano pomoću polja, a implementaciju liste odaberite sami. Ne trebate implementirati sve funkcije iz atp LIST, nego samo one koje su vam potrebne u zadatku. Na binarnom stablu implementirajte sve operacije iz atp DICTIONARY osim DELETE. Ulazni podaci: niz znakova koji čine elemente liste koje treba sortirati; ubacujte ih u BST točno redom kojim su navedeni. Izlazni podaci: 3 retka: u prvom su elementi uzlazno sortirane liste, u drugom silazno sortirane, a u trećem je (za kontrolu) PREORDER obilazak konstruiranog stabla. Na primjer, za ulazne podatke: MIRKO treba ispisati: uzlazno sortirana lista: IKMOR silazno sortirana lista: ROMKI preorder: MIKRO Funkcija insert mi uđe u beskonačnu petlju :
Jel može pomoć u pronalasku greške? |
output generated using printer-friendly topic mod. Vremenska zona: GMT + 01:00.