frutabella (napisa): |
Moram sazeti m uzlazno sortiranih listi pomocu hrpe. Hrpa je prikazana pomocu pointera, a lista je vezana lista prikazana pomocu pointera. Kako da ucitam m sortiranih listi? :S |
Kod: |
#include <stdio.h> #include<stdlib.h> #include<ctype.h> typedef struct celltag{ char c; struct celltag *next; }celltype; typedef celltype *List; typedef celltype *position; position LiMakeNull(List *Lp){ *Lp=(celltype*)malloc(sizeof(celltype)); (*Lp)->next=NULL; return (*Lp); } void LiInsert (char x, position p, List *Lp) { position temp; temp=p->next; p->next=(celltype*)malloc(sizeof(celltype)); p->next=x; p->next->next=temp; } position LiNext(position p, List Lp) { if (p->next == NULL) { printf("NEXT: Kriva pozicija."); exit(1); } return p->next; } int main (void){ int m, i, j; char c; List L[10]; position p[10]; printf("Koliko listi zelimo sazeti?\n"); scanf("%d", m); for(i=1; i<=m; ++i) p[i]=LiMakeNull(&L[i]); for(i=1; i<=m; ++i) { printf("U listu %d ubaci sljedece charove:\n", i); for(j=0; j<20; ++j) { scanf("%c", c); if (isalpha('c')==0) { i++; break; } else LiInsert(c, p[i], &L[i]); p[i]=LiNext(p[i], L[i]); } } return 0; } |
frutabella (napisa): |
mislim da imam problema s prog2, nesto ovako se meni cini ok, ali ne radi, ne znam u cemu je problem.
Lista sadrzi elemente tipa char. Prepostavka je da ima najvise 10 lisi, a svaka ima najvise 20 elemenata. Ovdje kao zelim stvoriti liste L[1], L[2], ... , L[m], a svaka od njih ima svoje pozicije p[1], ... p[m]. I for petljom popunjavam. Ali nesto ne stima... |
Kod: |
scanf("%d", m); . . . scanf("%c", c); |
Kod: |
int main () { int br, len; char p[100]; Relation R; ReMakeNull (&R); domain1 student; domain2 kolegij; printf("Za unos studenta birajte 1. \n"); // ovdje idu ostali printfovi za ostale unose while (1) { printf ("Unesite broj: "); scanf ("%d", &br); switch (br) { case 1: { printf("Ime studenta: \n"); alociraj1 (&student); unesi_studenta (student, &R); break; } /* (...) */ |
Kod: |
void alociraj1 (domain1 *student) { char str[100]; scanf(" %[^\n]", str); (*student) = (domain1)malloc((strlen(str)+1)*sizeof(char)); strcpy(*student, str); } void unesi_studenta (domain1 student, Relation *Rp) { domain2 kolegij; int flag=1; // pretpostavljamo da ako se unosi student da je on upisao barem jedan kolegij while (flag) { printf ("Unesi kolegij koji je %s upisao/la: \n", student); alociraj2 (&kolegij); ReRelate ( Rp, student, kolegij); printf ("Ima li jos kolegija koje je upisao/la? (1/0)"); scanf ("%d", &flag); } } void alociraj2 (domain2 *kolegij) { char str[100]; scanf(" %[^\n]", str); (*kolegij) = (domain2)malloc((strlen(str)+1)*sizeof(char)); strcpy(*kolegij, str); } void ReRelate (Relation *R, domain1 d1, domain2 d2) { rcelltype *poc1, *poc2, *p, *t; int ima1 = MaCompute1(R->M1, d1, &poc1); int ima2 = MaCompute2(R->M2, d2, &poc2); if (ima1) for (p = poc1; p; p = p->next1) if ( !strcmp (p->d1, d1) && !strcmp(p->d2, d2)) return; t = (rcelltype*)malloc(sizeof(rcelltype)); strcpy (t->d1, d1); strcpy (t->d2, d2); t->next1 = ima1 ? poc1 : NULL; t->next2 = ima2 ? poc2 : NULL; printf("rerelate\n"); MaAssign1(&R->M1, d1, t); MaAssign2(&R->M2, d2, t); } void MaAssign1 (Mapping1 *Mp, domain1 d, range r) { if ((*Mp) == NULL) { printf("maassign1\n"); (*Mp) = (mcelltype1*)malloc(sizeof(mcelltype1)); // <- tu prestaje raditi printf("maassign1\n"); strncpy ((*Mp)->d, d, strlen(d)); (*Mp)->r = r; (*Mp)->left = (*Mp)->right = NULL; return; } // itd. } |
Zadaća - string.c | |||
Description: |
|
Download |
|
Filename: | Zadaća - string.c | ||
Filesize: | 23.68 KB | ||
Downloaded: | 154 Time(s) |
Kod: |
t = (rcelltype*)malloc(sizeof(rcelltype));
strcpy (t->d1, d1); strcpy (t->d2, d2); |
Kod: |
t->d1 = (domain1)malloc(strlen(d1)+1);
t->d2 = (domain1)malloc(strlen(d2)+1); |
Kod: |
rerelate
maassign1 maassign1 |
Kod: |
(*Mp) = (mcelltype1*)malloc(sizeof(mcelltype1));
printf("maassign1\n"); strncpy ((*Mp)->d, d, strlen(d)); |
Kod: |
void ReCompute2 (Relation R, domain1 d1, Set2 *S2p) {
SeMakeNull2(S2p); rcelltype *p; if (R.M1) //R.M1 je pokazivac na strukturu printf("R.M1 nije null\n"); int ima = MaCompute1(R.M1, d1, &p); if(!ima) return; (...) } |
Kod: |
int MaCompute1 (Mapping1 M, domain1 d, range *rp) {
if(M == NULL){ printf("M je null\n"); return 0; } (...) } |
Kod: |
R.M1 nije null
M je null |
Kod: |
#include <stdio.h>
int main(void) { int *p; printf("%p\n", p); return 0; } |
Kod: |
int x;
printf("%d\n", x); |
Kod: |
(*Mp) = (mcelltype1*)malloc(sizeof(mcelltype1));
strncpy ((*Mp)->d, d, strlen(d)); |
Kod: |
(*Mp)->d = (domain1)malloc(strlen(d)+1); |
Kod: |
(*Mp)->d = (domain2)malloc(strlen(d)+1); |
Zadaća - string.c | |||
Description: |
|
Download |
|
Filename: | Zadaća - string.c | ||
Filesize: | 23.85 KB | ||
Downloaded: | 124 Time(s) |
output generated using printer-friendly topic mod. Vremenska zona: GMT + 01:00.