why my functions bring garbage collections

Pages: 12
for ( ptrM = front->next; ptrM != back; ptrM->next )//Error??

ptrM->next isn't moving the pointer along.
Maybe you meant to do like this. ptrM = ptrM->next.


yes, it was the mistake, but I gated


1 2 3 4 5
No mach
No mach
the element is:3
No mach
No mach
front 1 2 0 4 5 back // the swap is not working!!!!, I check and I can not find the
problem , any suggestion, it has to put the 3 in the front
like this 3 1 2 4 5.
My, this is hard work.
Post your code as it is now so we can see where you are.
The code is it:

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
 template <class T>
void Queue<T>::Mutofront(const Queue<T>& MuveElement,int n)
{
    Node<T> *ptrM;
    

       for ( ptrM = front->next; ptrM != back; ptrM->next = ptrM->next ){

         if ( n == ptrM->info){

              cout<<"the element is:"<<ptrM->info<<endl;

                         DataType *temp  = &ptrM->info;//Here is the swap that is not working

                          ptrM->info = front->info;

                         front->info = *temp;

                          delete ptrM;

                        
                 

             }
         else

                    cout<< "No mach"<<endl;

   }

          
}
                                     
This is still wrong - I don't think you understand what you are doing at all.
Please provide ALL the code.
Here are the function definitions and the implementations, just the functions where the program call in main

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
//.h

template <class T>
struct Node {
        T info;
        Node<T> *next;
};

template <class T>
class Queue
{
public:
        Queue( );
        Queue( const Queue<T> & ap );
        ~Queue( );
      void enqueue( const DataType & ele); 

       there are more function members........

private:
        Node<T> *front;
        Node<T> *back;
        Node<T> header;


\\.cpp

template <class T>
Queue<T>::Queue( )// the cosntructor
{
        front= back = &header;
}

template <class T>
void Queue<T>::enqueue( const T & ele )
{

        Node<T> *ptr = new Node<T>;
        ptr->info = ele;
        back->next = ptr;
        back = ptr;


}

ANY IDEA????
Look, guy, I can understand that you're impatient and you want an answer as soon as possible, but saying over and over again "ANY IDEA???" isn't going to get you faster responses. Actually, your attitude has cost at least one response. I decided not to reply to your threads because of your impatience. Understand this: none of us has any obligation to reply to any threads. We do it because we want to. If you get a response and it's helpful, you should feel thankful. Not just because someone was kind enough to help you for nothing, which itself is enough, but also because someone happened to look at your question, and managed to figure out what was wrong, perhaps even a couple hours after you posted it. Even though most of the experienced posters live in the Western hemisphere, a lot of posters who primarily ask questions live at the opposite side of the world, meaning sometimes six or even twelve hours can pass without a single reply. Do they complain? No. They know their place. Beggars can't be choosers.
You can't wait four hours? Are you on a deadline or something? To answer your last post, here's an idea: if you're in that much of a hurry, why don't you, oh, I don't know... try solving it yourself?
try solving it yourself?


This.
Sorry, I have 2 week with this problem, I am very thank for all of you guy, and for you helios, I just do not have enough time to finish sorry for the inconvenient .I will do not do again.........

THANKS.............................And God Bless you
Topic archived. No new replies allowed.
Pages: 12