Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Kako do mreze pointera?

[es] :: C/C++ programiranje :: C/C++ za početnike :: Kako do mreze pointera?

[ Pregleda: 3808 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Mala-drakula
Vilotijevic Nada

Član broj: 93159
Poruke: 1
*.verat.net.



Profil

icon Kako do mreze pointera?28.04.2006. u 19:54 - pre 221 meseci
Trebalo bi da odradim u C-u unos elemenata matrice gde bi se matrica pamtila kao mreza pointera. Imam ideju da to realizujem pomocu dvostrukih pointera ali ne radi kako treba.Znam da sam previse iskomplikovala ali nikako ne radi? Zasto? Hvala
Code:

typedef struct cvor {
float sadrzaj;
struct cvor *levo;
struct cvor *desno;
  } BCVOR;
   main()
{  int n,m,i,j;
   float k;
   BCVOR *koren,*novi,*p,*q,*r,*d; 
   koren=NULL;
    
   printf(" Unesi broj vrsta matrice\n");
   scanf("%d",&n);
   printf("Unesi broj kolona matrice\n");
   scanf("%d",&m);
   printf("Unesi elemente matrice");

 for(i=1;i<=n;i++)  {  if (!(koren==NULL))  {    
                                                                            r=q;
                                                                            q=q->levo;
                                                                            p=q;
                                                                            
                                                                         }
                       for(j=1;j<=m;j++)   {
                                                         printf("\n a[%d][%d]=",i,j);
                                                         scanf("%f",&k);
                                                         novi=(BCVOR*)malloc(sizeof(BCVOR));novi->sadrzaj=k;
                                                    novi->desno=NULL;
                                                    novi->levo=NULL;
if(i==1&&j==1){
koren=novi;p=q=koren;}
if(i==1&&j==1)continue;
                                                         if(koren==q)  { 
                                                                                    p->desno=novi;
                                                                                    p=p->desno;  
                                                                                 }
             else{ if(j==1) {p=novi;r->levo=novi;}

                                                               else {   r=r->desno;
                                                                            p->desno=novi;
                                                                            p=p->desno;
                                                                            r->levo=novi;
                                                                       }
                                                         }
  
                                                 r=q;                                                                                                                                                                                                                                                                                                                                                                                                               
                                                          
                                                 }
                 
                     }
 
Odgovor na temu

opmo
Beograd

Član broj: 87495
Poruke: 75
*.dynamic.sbb.co.yu.



Profil

icon Re: Kako do mreze pointera?23.11.2006. u 00:19 - pre 214 meseci
Ako vec hoces mrezu pointera definisi ih sa npr
int **matr_A,**matr_B;

nema potrebe za strukturom i silnim pointerima ...

Ako nisi resila ili te zanima ta tema i dalje,ja sam pisao za domaci nesto na tu foru.Mail mi je [email protected]
 
Odgovor na temu

peromalosutra
Ivan Rajkovic
Software engineer
Berlin

Član broj: 54774
Poruke: 878
*.teol.net.



+148 Profil

icon Re: Kako do mreze pointera?07.12.2006. u 05:52 - pre 214 meseci
princip je sledeći:
Code:

int **grid;
grid = new grid*[n];
for (int i=0; i<n; i++)
   grid[i]=new grid[n];


ps: sad tek vidim da je ovo c forum. Samo zamjeni c++ operator new sa malloc i radice.
 
Odgovor na temu

[es] :: C/C++ programiranje :: C/C++ za početnike :: Kako do mreze pointera?

[ Pregleda: 3808 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.