-
November 8th, 2003, 03:17 AM
#1
Member
-
November 8th, 2003, 08:04 PM
#2
Maybe the errors are from the smilies in your code. Click edit on your post and check the box to disable the smilies. I hope you get a real answer to your question, but I don't know c++. You may also want to look into the code tags.
["code"]
code here
["/code"]
without the quotes of course. Good luck.
-
November 8th, 2003, 08:35 PM
#3
Here's the code, reformatted to look okay. I don't know C++, but there is apparently a syntax error on line 186, which is:
Code:
CLList::size_type CLList<Item>::size() const {
Anyway, here's the code properly formatted code. Sorry about the long lines:
Code:
#include <iostream>
#include <cstdlib>
#include <cassert>
#include "CLList.h"
namespace uprm_icom4035 {
//////////////// DO NOT MODIFY THESE FUNCTIONS //////////////////////////////
template <typename Item>
void CLList<Item>::-Print_list(ostream& out) const {
cl_list_node<Item> *temp = NULL;
// print each data value on a separate line
for (temp = header->next; temp != header; temp = temp->next) {
out << temp->data << endl;
}
}
// Return the element at the current location of the iterator
// Note: This function will throw a string exception if the
// Iterator is not on a valid node with data (i.e. the header)
template <typename Item>
Item& CLLIterator<Item>::get_data() const {
if (has_data()){
return curr->data;
}
else {
string msg = "CLLIterator<Item>::get_data()Error: Iterator has no data to return.";
throw msg;
}
}
// Constructor for the iterator
template <typename Item>
CLLIterator<Item>::CLLIterator(cl_list_node<Item>* hdr, cl_list_node<Item>* tail):Iterator<Item>() {
this->hdr = hdr;
this->tail = tail;
this->curr = hdr;
}
//////////////////////////////////////////////////////////////////////////
/************* START ADDING FOR CODE FROM HERE **************************/
/////********IMPLEMENTACION DEL ITERADOR DE LA LISTA REDONDA**********///////////
//ARREGLO bien pues no chekea bien si esta vacio no hay tail aki
template<typename Item>
bool CLLIterator<Item>::has_data()const{
return this->curr!=header;
//return (this->hdr == header && this->curr==header && this->tail==header);
}
//SUPER IMP AKI QUE SI SIGUE HACIA ALFRENTE
template<typename Item>
void CLLIterator<Item>::next(){
if(curr->next != header)
curr = curr->next;
}
template<typename Item>
void CLLIterator<Item>::reset(){
curr = hdr;
}
template<typename Item>
void CLLIterator<Item>: rev(){
if(curr->prev!=header)
curr = curr->prev;
}
//*************COMIENZA IMPLEMENTACION DE CLLIST*****************//
//Constructor de la lista
template<typename Item>
CLList<Item>::CLList(){
header = new cl_list_node<Item>();
header->next = header;
header->prev=header;
}
//COpy constructor
//CHEKEAR
template<typename Item>
CLList<Item>::CLList(const CLList<Item>& L){
for(CLLIterator<Item>* iter = L.first(); iter.has_data(); iter->next()){
this->insert(iter->get_data());}
}
template<typename Item>
CLList<Item>::~CLList(){
this->make_empty();
delete header;
header = NULL;
}
//OPERATOR = usa el codigo de el copy pero devuelve el this
template<typename Item>
const CLList<Item>& CLList<Item>: perator=(const CLList<Item>& L) {
if(this==&L) {
return *this;
}
else {
this->make_empty();
for(CLLIterator<Item>* iter = L.first(); iter.has_data(); iter->next()) {
this->insert(iter->get_data());
}
return *this;
}
}
//Funcion de FIND
template<typename Item>
Iterator<Item>* CLList<Item>::find(const Item& obj) const{
cl_list_node<Item>* temp = NULL;
for(temp = header->next; temp != header; temp = temp->next){
if(temp->data==obj) {
return new CLLIterator<Item>(temp);
}
}
return NULL;
}
//Funcion de first devuelve iterador al primer elemento
template<typename Item>
Iterator<Item>* CLList<Item>::first() const {
CLLIterator<Item>* temp = new CLLIterator<Item>(header->next);
return temp;
}
template<typename Item>
void CLList<Item>::insert(const Item& obj) {
cl_list_node<Item>* temp=NULL, *temp2=NULL;
temp = new cl_list_node<Item>;
if(this->is_empty()){
temp->data=obj;
header->next = temp;
temp->prev = header;
temp->next = header;
header->prev = temp;
}
else{
for(temp2=header->next; temp2!= header; temp2 = temp2->next) {
if(temp2->data < obj || temp2->next=header) {
temp->data = obj;
temp->next = temp2->next;
temp->prev = temp2;
temp2->next->prev = temp;
temp2->next = temp;
return;
}
}
}
}
//Funcion de borrar un elemento
template<typename Item>
bool CLList<Item>::erase(const Item& obj) {
cl_list_node<Item>* temp=NULL, *temp2=NULL;
if(this->is_empty()) {
return false;
}
else {
for(temp2=header->next; temp2!=header; temp2=temp2->next) {
if(temp2->data = obj) {
temp2->prev->next=temp2->next;
temp2->next->prev = temp2->prev;
delete temp2;
return true;
}
}
}
return false;
}
template<typename Item>
CLList::size_type CLList<Item>::size() const {
size_type amount = 0;
for(cl_list_node<Item>* temp = header->next; temp != header; temp=temp->next) {
++amount;
}
return amount;
}
template<typename Item>
bool CLList<Item>::is_empty() const {
return header->next==header;
}
template<typename Item>
void CLList<Item>::make_empty() {
while(!is_empty()) {
erase(header->next->data);
}
}
}
-
November 9th, 2003, 01:24 AM
#4
i personally think that the errors make perfect sense...i havent fully looked through your code and understood all of it, but your error report sounds like you made little errors here and there. if there is an error you dont understand, then just click on it and then click F1 and normally a little help window will pop up and will explain to you what the error is and sometimes how to fix it. Also, the comments in spanish dont help me understand the code you might want to change them to enlish porque mi espanol es muy malo
Support your right to arm bears.
^^This was the first video game which i played on an old win3.1 box
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|