doubly linked list on fire, need some help

hello guys. first of all i have to program a list for school. first i tried a version without having a class for saving the first and last ListNode and it worked well. now i have to write a header class which contains the first and last element. i gave my best but the compiler has a problem with my type type definition, E.g. CQueue doesnt name a type.

id appreciate it, if anyone could check out. thank you.

my Dataclass:

CPJob.h
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
#ifndef _CPUFREQ_H
#define _CPUFREQ_H 1

//
//  class  CPJob  defines  a  simple  printjob  with  id  and  text
//
class CPJob {
private:
	long lPid;
	char *szText;

public:
	//constructor
	CPJob(char*, long); //inits  text-field  and process-id

	//destructor
	~CPJob(void);

	//accessor s
	void setText(char*); // sets  text-field
	char* getText(void); // returns  text-field
	long getPid(void); // returns  process-id
};

#endif /* _CPUFREQ_H */ 



CPJob.cpp
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
#include  <cstring>
#include  "CPJob.h"

//constructor  ::sets  text-field  and  process-id
CPJob::CPJob(char *_szText, long _lPid) {
	lPid = _lPid;
	szText = new char[std::strlen(_szText) + 1];
	std::strcpy(szText, _szText);
}

//destructor  ::deletes  allocated  mem  for  text-field
CPJob::~CPJob(void) {
	delete[] szText;	// nur für Arrays! szText ist ein Zeiger auf array
}

//accessor::sets  text-field
void CPJob::setText(char * _szText) {
	szText = _szText;
}

//accessor::returns  text-field
char* CPJob::getText(void) {
	return szText;
}

//accessor::returns  process  id
long CPJob::getPid(void) {
	// TODO
	return lPid;
}


This was my New type of data i want to work with. Now the Queue Class

CQueue.h
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
/*
 * CQueue.h
 *
 *  Created on: 04.10.2012
 *      Author: IzO
 */

#ifndef CQUEUE_H_	//Beim Linken wird die Headerdatei nur 1 Mal eingebunden! Wenn definiert nicht abarbeiten
#define CQUEUE_H_

#include  "CPJob.h"
#include "CQueueContainer.h"

class CQueue {
private:
	CPJob* data; //Daten
	CQueue* next; //zeigt auf das nächste Element
	CQueue* prev; //zeigt auf das vorherige Element


public:
	CQueue(); //Konstruktor --> Objekt mit Werten versehen

	~CQueue(); //Destruktor --> Löschen des Objekts

	void push(CPJob*);	// neues Queueelement hinzufügen
	void pop();			//Löscht das erste Element --> FIFO
	void printJobs();	//gibt die Queue aus
};

#endif /* CQUEUE_H_ */ 


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
80
81
82
83
84
85
86
87
88
/*
 * CQueue.cpp
 *
 *  Created on: 04.10.2012
 *      Author: IzO
 */
#include <iostream>
#include "CPJob.h"
#include "CQueue.h"
#include "CQueueContainer.h"

using namespace std;

CQueueContainer* list=new CQueueContainer();

CQueue::CQueue()
{
	next = NULL;
	prev = NULL;
	data = NULL;
}


CQueue::~CQueue()
{
	delete this;
}

void CQueue::push(CPJob* cj) {
	CQueue* temp1 = new CQueue;
	temp1 = list->getFirst();

	CQueue* temp2 = new CQueue;
	temp2 = list->getLast();

	if (list->getCnt() == 0)
	{
		temp1->data = cj;
		list->setFirst(temp1);
		list->setLast(list->getFirst());
		list->setCnt((list->getCnt())+1);
		//first = new CQueue;
		//first->data = cj;
		//last = new CQueue;
		//last = first;
	}
	else
	{
		list->getLast()->next = new CQueue();
		//last->next = new CQueue;
		list->setLast(list->getLast()->next);
		//last = last->next;
		list->getLast()->prev = temp2;
		//last->prev = temp2;
		list->getLast()->data = cj;
		//last->data = cj;
		list->setCnt((list->getCnt())+1);
	}
}

void CQueue::pop()
{
	CQueue* temp = new CQueue;
	temp = list->getFirst();

	temp = temp->next;
	list->setFirst(temp);
	cout << "Das gepoppte Element hat die id "<< list->getFirst()->prev->data->getPid() << ": " << list->getFirst()->prev->data->getText() << endl;
	cout << endl;
	//first->prev = NULL;
	delete list->getFirst()->prev;
	list->getFirst()->prev = NULL;
	list->setCnt(list->getCnt()-1);

}

void CQueue::printJobs() {
	CQueue* temp = new CQueue;
	temp = list->getFirst();

	cout << "PrintJobs - Queue: " <<endl;
	while (temp != NULL) {
		cout << temp->data->getPid()<<temp->data->getText()<< endl;
		temp = temp->next;
	}
	cout << endl;

}


CQueueContainer.h
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
/*
 * CQueueContainer.h
 *
 *  Created on: 10.10.2012
 *      Author: IzO
 */

#ifndef CQUEUECONTAINER_H_
#define CQUEUECONTAINER_H_

#include "CPJob.h"
#include "CQueue.h"

class CQueueContainer
{
	private:
		CQueue* first;
		CQueue* last;
		int cnt;
		
	public:
		CQueueContainer();
		~CQueueContainer();
		
		CQueue* getFirst();
		CQueue* getLast();
		int getCnt();
		void setFirst(CQueue*);
		void setLast(CQueue*);
		void setCnt(int);
};


#endif /* CQUEUECONTAINER_H_ */ 


CQueueContainer.cpp
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
/*
 * CQueueContainer.cpp
 *
 *  Created on: 10.10.2012
 *      Author: IzO
 */



#include <iostream>
#include "CQueueContainer.h"

using namespace std;


CQueueContainer::CQueueContainer()
{
	first = new CQueue();
	first = NULL;
	last = new CQueue();
	last = 0L;
	cnt = 0;
}

CQueueContainer::~CQueueContainer()
{
	delete this;
}

CQueue* CQueueContainer::getFirst()
{
	return first;
}

CQueue* CQueueContainer::getLast()
{
	return last;
}

int CQueueContainer::getCnt()
{
	return cnt;
}

void CQueueContainer::setFirst(CQueue* newFirst)
{
	first = newFirst;
}

void CQueueContainer::setLast(CQueue* newLast)
{
	last = newLast;
}

void CQueueContainer::setCnt(int newCnt)
{
	cnt = newCnt;
}


main.cpp
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
#include  <iostream>
#include  "CPJob.h"
#include  "CQueue.h"

//function  ::fills  queue  with  CPJob  objects
void fillQueue(CQueue* pQueue, int num) {
	CPJob *pPJob;
	for (int i = 0; i < num; i++) {
		pPJob = new CPJob("text", i);
		pQueue->push(pPJob);
	}
}

//driver  ::simple  test
int main(int argc, char* argv[]) {
	CQueue *pQueue;
	pQueue = new CQueue();	// Der Speicher wird mit new reserviert, als Rückgabeparameter gibt ein pt eauf das neue Objekt
							// Std-Konstruktor wird aufgerufen, man kann verschiedene Konstr. definieren, die Parameterabhängig sind.
	fillQueue(pQueue, 10);
	pQueue->printJobs();
	pQueue->pop();
	pQueue->printJobs();
	pQueue->pop();
	pQueue->pop();
	pQueue->pop();
	pQueue->printJobs();

	return 0;
}
Topic archived. No new replies allowed.