queue problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
////////////////////////////////////////////////////////////////
//const int MAX = 10;

template < class T > //template
class Kuyruk
{
      private:
              int sayac;
              T deger[];
              int tersayac;
              
      public:
           class Full
           {  };
           
           class Empty
           { };
           
             Kuyruk(): sayac(-1),tersayac(0)
             { }
             
             void put(T var) //put
             {
                 T* ptr = new T;
                 *ptr = var;
                  deger[++sayac] =  *ptr;
                  
                 
             }
             
             T get() //show data
             {
                    // if(tersayac > sayac)
                      //   throw Empty();
                   int bastaki = tersayac;
                   ++tersayac;
                   return deger[bastaki];
             }
                  
};
             
int main(int argc, char *argv[])
{
    
    Kuyruk<int> s1;
    
    try
    {
    s1.put(4);
    s1.put(53);
    s1.put(35);
    
    cout << "1: " << s1.get() << endl;
    cout << "2: " << s1.get() << endl;
    s1.put(90);
    cout << "3: " << s1.get() << endl;
    cout << "4: " << s1.get() << endl;
  //Error line cout << "5: " << s1.pop() << endl;
    }
    
    catch(Kuyruk<int>::Full)
     {
             cout << "Kuyruk Full...\n";
     }
     catch(Kuyruk<int>::Empty)
     {
             cout << "Kuyruk empty....\n";
     } 
   
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

That's doesn't work.it compiles,but values aren't true.i think my problem is put .what can i do for it ?
help me!!!!
i don't understand you..you don't help me.Do you hate me?i solve it but now that's working but program ending ooo error i don't understand.sorry for my english.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//kuyruk yapısı

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
////////////////////////////////////////////////////////////////
//const int MAX = 10;

template < class T > //template
class Kuyruk
{
      private:
              int sayac;
              T deger[];
              int tersayac;
              
      public:
           class Full
           {  };
           
           class Empty
           { };
           
             Kuyruk(): sayac(0),tersayac(0)
             { }
             
             void put(T var) //verileri ekle
             {
                 T* ptr = new T;
                 *ptr = var;
                 deger[++sayac] = *ptr;
            
                }
             
             T get() //verileri göster
             {
                     //if(tersayac > sayac)
                      //   throw Empty()
                   tersayac++;
                   return deger[tersayac];
              
             }
                  
};
             
int main(int argc, char *argv[])
{
    
    Kuyruk<int> s1;
    
    int s = 0;
    int deger = 0;
    char secim;
    
    
    do
     {
  
        cout << "Enter value for eqeue: "; 
        cin >> deger;
        s1.put(deger);
         s++;
      cout << "Do another?(y/n)? ";
       cin >> secim; 
     } while(secim == 'y');
     
           for(int i = 0; i < s; i++)
             cout << "Value " << i+1 << " is " << s1.get() << endl;
               
   
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
First of all, since most people on the fora are from America, they are probably asleep at 8 in the morning. Second, what do secim, deger, Kuyruk and tersayac mean. And third what is the program actually doing?
Do you hate me?
If your attitude remains.
Ok.Sorry i'm not living in America.This program a queue.i want to add data to Kuyruk(mean queue).but i don't to achieve it.This program is compiling but After working..that's boomm.collapse.i think my problem get or put functions.Thank you
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//Queue

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
////////////////////////////////////////////////////////////////
//const int MAX = 10;

template < class T > //template
class queue
{
      private:
              int counter;
              T value[];
              int recounter;
              
      public:
           class Full
           {  };
           
           class Empty
           { };
           
             queue(): counter(0),recounter(0)
             { }
             
             void put(T var) //add data
             {
                 T* ptr = new T;
                 *ptr = var;
                 value[++counter] = *ptr;
            
                }
             
             T get() //show data
             {
                       recounter++;
                   return value[recounter];
             }
                  
};
             
int main(int argc, char *argv[])
{
    
    queue<int> s1;
    
    int s = 0;
    int value = 0;
    char choice;
    
    
    do
     {
  
        cout << "Enter value for eqeue: "; 
        cin >> value;
        s1.put(value);
         s++;
      cout << "Do another?(y/n)? ";
       cin >> choice; 
     } while(cohice == 'y');
     
           for(int i = 0; i < s; i++)
             cout << "Value " << i+1 << " is " << s1.get() << endl;
               
   
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
Last edited on
I think your problem is that your program never initializes the array value[]. Also, since you are using a queue(this also applies to lists and stacks), you should put things in and take them off using nodes, but look that up online.
Topic archived. No new replies allowed.