why my functions bring garbage collections

Pages: 12
Queue Operations
Enter -1 to finish


1 2 3 4 -1
The constructor is
1
2
3
4
5
6
template <class DataType>
Queue<T>::Queue( )
{
        f = b = &header;
}
The function print in console is

Move to the front --->:0
Queue contains: front 11583160 134516988 1 2 3 4 back

1
2
3
4
5
6
7
8
9
10
11
12
void Queue<DataType>:: Display( ) const
        Node<T> *ptr;   // Iterates through the queue
        if ( f== b)
                cout << "The Queue is Empty " << endl;
        else
        {
                cout << "f ";
         for ( ptr = f ; ptr != NULL ; ptr = ptr->next )
                cout << ptr->info << " ";
                cout << "b" << endl;
    }
}


I just call normally the queue with the function prototype.
Last edited on
what?
:O ...
what is the joke?????
We don't get what you're asking.
Can some one give to me which is wrong with the code?

que.cpp: In member function âvoid Queue<DataType>::Mutofront(const Queue<T>&, int) [with DataType = int]â:
P:55: instantiated from here
que.cpp:152: error: conversion from âintâ to non-scalar type âNode<int>â requested
que.cpp:156: error: cannot convert âNode<int>â to âintâ in assignment

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
template <class T>
void Que<T>::Mutotofront(const Que<T>& ele,int n)
{
 Nod<T> *ptrM;
 Nod<T> *ptrM2;
       for ( ptrM = f; ptrM != b; ptrM->next ){

         if ( n == ptrM->info){

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

           for ( ptrM2 = f ; ptr2 != b; ptrM2->next ){

                          Node<DataType> temp*  = ptrM->info;

                    ptrM->info = ptrM2->info;

                        ptrM->info = temp;

                        delete ptrM;

                        delete ptrM2;
                 }

             }
         else

                    cout<< "No mach"<<endl;

   }

         
}
What types are ptrM->info, f, b instance of?
f = front
b = back

they are variable member


and ptrM is a variable pointer
I want to know the exact type
in the private sections

1
2
3
4
private:
        Node<T> *front;
        Node<T> *back;
        Node<T> header;
What about info?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
template <class T>
struct Node {
        T info;
        Node<T> *next;
};

template <class T>
class Queue
{
public:
        Queue( );
        Queue( const Queue<T> & ap );
        ~Queue( );
        there are more function members........
private:
        Node<T> *front;
        Node<T> *back;
        Node<T> header;
        );
};

Last edited on
Node<DataType> temp* = ptrM->info;
Info is of type T, not Node<T>
Tha is the error after I change line 14 in Motofront() .....function to

Node<T> temp* = ptrM->info;
to
T temp* = ptrM->info;

queue2.cpp: In member function âvoid Queue<T>::Motofront(const Queue<T>&, int) [with DataType = int]â:
PruebaLinkedQueue.cpp:55: instantiated from here
queue2.cpp:153: error: invalid conversion from âintâ to âint*â//line 14 Mutotofront()function
queue2.cpp:157: error: invalid conversion from âint*â to âintâ//line 16 Mutotofront()function
Add an '&' before 'ptrM->info'
I did and I have to put a * in the line 18 too


But I continuous with the super loop tha bring extras number I do not enter , they just generate


This is the answer of all of thes with the functionvoid Que<T>::Mutotofront(const Que<T>& ele,int n)
No mach
No mach
No mach
No mach
No mach
No mach
No mach
No mach
No mach
No mach
No mach
No mach
No mach
No mach...................
1
2
from main with without 
void Que<T>::Mutotofront(const Que<T>& ele,int n) 



1
2
3
4
5
6
7
8
Enter the element of the list type -1 to finish 


1 2 3 4 -1

front 11583160 1 2 3 4 back// those number in bold the program generate and I do no know the reason
The   QueueLinkedLIst has 5-1 // apparently the list has 4 elements, so do not count the 11583160 numbers



Any idea to finish with the super loooooooop!!!!!
Any idea guys??????
Hi Bazzy can you tell me a idea of thease
This is the run from main

Queue Operations
Enter -1 to finish the element os the list


1 2 3 4 -1

front 1 2 3 4 back

Enter the element to move Front --->:1
the element is:1

*** glibc detected *** ./a.out: free(): invalid pointer: 0x006a0ff4 ***
======= Backtrace: =========
/lib/libc.so.6[0x5d5a68]
/lib/libc.so.6(__libc_free+0x78)[0x5d8f6f]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xade801]
./a.out[0x8048d5e]
./a.out(__gxx_personality_v0+0x2f4)[0x80489e0]
/lib/libc.so.6(__libc_start_main+0xdc)[0x5874e4]
./a.out(__gxx_personality_v0+0x65)[0x8048751]

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

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

         if ( n == ptrM->info){

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

                         DataType *temp  = &ptrM->info;

                         ptrM->info = front->info;

                       front->info = *temp;

                        delete ptrM;

                        
                 

             }
         else

                    cout<< "No mach"<<endl;

   }

          
}
                                     



4
5
Node<T> *ptrM;
// never allocating with new 

21
22
delete ptrM;
// deleting an invalid pointer 

Last edited on
Ok

I did the suggestion and I continue with infinite "not mach" output, What can I do, what is wrong in the for loop that never mach the value I say to mach??????????????????
Pages: 12