+ Reply to Thread
Results 1 to 2 of 2

Thread: "самостоятелна работа" No. 2

  1. #1

    "самостоятелна работа" No. 2

    Задача II.2.1.12
    Да се състави програма, която създава динамичен стек S, след което установява N-я след върха елемент в стойност A, като първите N-1 елемента запазват стоите стойности.

    PHP Code:
    #include<iostream.h>
    int br=0;

    struct elem
    {
          
    int key;
          
    elem *next;
    }*
    s1=NULL, *p, *s2=NULL;
    void push(int nelem *&start);
    int pop(int &n,elem *&start);
    void insert();


    void insert()
    {    
        
    int n=1;

        while(
    n!=0)  // 0 za izhod
        
    {
            
    cout<<"\n Vuvedi cifra: ";
            
    cin>>n;
            if (
    n!=0push(n,s1);
        }

        
    cout<<endl;
    }

    void push(int nelem *&start)
    {
          
    p=start;
          
    start=new elem;
          
    start->key=n;
          
    start->next=p;
          
    br++;
    }

    int pop(int &n,elem *&start)
    {
          if(
    start)
          {
                
    n=start->key;
                
    p=start;
                
    start=start->next;
                
    delete p;
                return 
    1;
          }
          else
          {
                return 
    0;
          }
    }


    void main()
    {
        
    insert();
          
    int mai;

          do
          {
                
    cout<<"\n Vuvedi chislo mejdy 1 i "<<br<<" !"<<endl;
                
    cout<<" m= ";
                
    cin>>m;

          }while(
    m<&& m>br);

     

            for(
    i=1;i<m;i++)
            {
                
    pop(a,s1);
                
    push(a,s2);
            }
            
    cout<<"\n Vuvedi nova stojnost "<<endl;
          
    cout<<" A=  ";
          
    cin>>a;
            
    s1->key=a;
            while(
    pop(a,s2))
                
    push(a,s1);
        
            while(
    pop(a,s1))
            
    cout<<" "<<a<<"\t";
          

    Code:
     Vuvedi cifra: 1
    
     Vuvedi cifra: 2
    
     Vuvedi cifra: 3
    
     Vuvedi cifra: 4
    
     Vuvedi cifra: 5
    
     Vuvedi cifra: 6
    
     Vuvedi cifra: 0
    
    
     Vuvedi chislo mejdy 1 i 6 !
     m= 3
    
     Vuvedi nova stojnost
     A=  99
     6       5       99      3       2       1      Press any key to continue
    Crazy forum admin
    PS: sorry for adverts, but bills ain't gonna pay themselves

  2. #2
    purva zadacha

    Code:
    /*str 29-.1.31 zadacha 
    a[][] {0 1 0 1
           1 0 1 0
           1 0 0 0 
           1 0 0 0 
           0 0 0 0} kaza che taka se p1lnila mrezata..
    i=o klaviatura j=o klaviatura
    v=a[i][j];
    void f(i,j,v) mislq che e rekursiqta za obikalqneto
    {if(a[i][j]==v)
    a[i][j];
    br++;
    {f(i+1,j);
        f(i-1,j);
        f(i,j+1);
        f(i,j-1);
        }
    }*/
    
    #include<iostream.h> 
    
    int A[4][5];
    int br=0;
    int i,j,v;
    
    void main()
    {
    
    cout<<"\n vavedi i i j: ";
    cin>>A[i][j];
    
    A[i][j];
    
        {    
        0, 1, 0, 1;
        1, 0, 1, 0;
        1, 0, 0, 0;
        1, 0, 0, 0;
        0, 0, 0, 0;
        }
    }
    
    void f(i,j,v)  //moje da se premahne za da se mahne unknown error-a
    {
        v=A[i][j];
    
        if(A[i][j]==v)
            A[i][j];
            br++;
        {
        f(i+1,j);
        f(i-1,j);
        f(i,j+1);
        f(i,j-1);
        }
    }
    vtora zadacha
    Code:
    
    
    Crazy forum admin
    PS: sorry for adverts, but bills ain't gonna pay themselves

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 28-09-2011, 05:26 PM
  2. Replies: 4
    Last Post: 16-05-2011, 02:59 PM
  3. "самостоятелна работа" No. 4
    By Bloo_uni in forum САА (C++)
    Replies: 1
    Last Post: 02-05-2011, 02:08 AM
  4. "самостоятелна работа" No. 3
    By Bloo in forum САА (C++)
    Replies: 1
    Last Post: 11-04-2011, 02:57 PM
  5. "самостоятелна работа" No. 1
    By Bloo in forum САА (C++)
    Replies: 1
    Last Post: 04-04-2011, 02:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts