realez Δημοσ. 30 Νοεμβρίου 2012 Δημοσ. 30 Νοεμβρίου 2012 Έχω προβληματιστεί πάρα πολύ με το παρακάτω. Θέλω η συνάρτηση Spliter να επιστρέφει 2 Pointer το head1 και το head2. Για να το κάνω αυτό σκεύτικα να φτιάξω άλλο ένα struct με 2 πεδία ptr1 και ptr2. Οπότε στη συνάρτηση δημιουργώ ένα αντικείμενο τύπου ptr, στο πρώτο πεδίο του(ptr1) βάζω το head1 και στο δευτερο πεδίο του(ptr2) το head2. αλλά μου βγάζει σφάλμα ptr does not namy a type. > struct spliter1 //thetika { int item; spliter1 *next; spliter1 *prev; }; spliter1 *head1; spliter1 *tail1; struct spliter2 //arnhtika { int item; spliter2 *next; spliter2 *prev; }; spliter2 *head2; spliter2 *tail2; public: struct ptr { spliter1 *ptr1; //ptr sto thetiko spliter2 *ptr2; //ptr sto arnhtiko }; ptr *retur; ptr* dll::Split() { spliter2 *temp2 = new spliter2; temp = head; do { node *temp = new node if( temp->item < 0 ) { spliter2 *temp1 = new spliter2; if(head2 == NULL) { head2 = temp1; tail2 = temp1; temp1 -> next = NULL; temp1 -> prev = NULL; temp1 -> item = temp -> item; } else { tail2 -> next = temp1; temp1 -> prev = tail2; tail2 = temp1; tail2 -> item = temp -> item; } } else { spliter1 *temp1 = new spliter1; if(head1 == NULL) { head1 = temp1; tail1 = temp1; temp1 -> next = NULL; temp1 -> prev = NULL; temp1 -> item = temp -> item; } else { tail1 -> next = temp1; temp1 -> prev = tail1; tail1 = temp1; tail1 -> item = temp -> item; } } temp = temp -> next; }while(temp != NULL); retur -> ptr1 = head1; retur -> ptr2 = head2; return retur; } Εδώ βάζω και όλο τον κώδικα μπας και χρειαστεί. ps: Πριν βάλω την split στο παιχνίδι δούλευε > #include <iostream> #include <cstdlib> using namespace std; class dll { private: struct node { int item; node *next; node *prev; }; node *head; node *tail; struct spliter1 //thetika { int item; spliter1 *next; spliter1 *prev; }; spliter1 *head1; spliter1 *tail1; struct spliter2 //arnhtika { int item; spliter2 *next; spliter2 *prev; }; spliter2 *head2; spliter2 *tail2; public: struct ptr { spliter1 *ptr1; //ptr sto thetiko spliter2 *ptr2; //ptr sto arnhtiko }; ptr *retur; dll(); bool isEmpty(); void Enqueue(int& element); int Dequeue(); int First(); int Last(); void Search(int element); void Print(); void Destroy(); ptr* Split(); void PrintSplit(spliter1* x, spliter2* y); void DestroySplit(spliter1* x, spliter2* y); }; dll::dll() { retur -> ptr1 = NULL; retur -> ptr2 = NULL; head = NULL; tail = NULL; head1 = NULL; tail2 = NULL; head2 = NULL; tail2 = NULL; } ptr* dll::Split() { spliter2 *temp2 = new spliter2; temp = head; do { node *temp = new node if( temp->item < 0 ) { spliter2 *temp1 = new spliter2; if(head2 == NULL) { head2 = temp1; tail2 = temp1; temp1 -> next = NULL; temp1 -> prev = NULL; temp1 -> item = temp -> item; } else { tail2 -> next = temp1; temp1 -> prev = tail2; tail2 = temp1; tail2 -> item = temp -> item; } } else { spliter1 *temp1 = new spliter1; if(head1 == NULL) { head1 = temp1; tail1 = temp1; temp1 -> next = NULL; temp1 -> prev = NULL; temp1 -> item = temp -> item; } else { tail1 -> next = temp1; temp1 -> prev = tail1; tail1 = temp1; tail1 -> item = temp -> item; } } temp = temp -> next; }while(temp != NULL); retur -> ptr1 = head1; retur -> ptr2 = head2; return retur; } bool dll::isEmpty() { return (head == NULL) ? true : false; } void dll::Enqueue(int& element) { if(isEmpty()) { node *temp = new node; head = temp; tail = temp; temp -> prev = NULL; temp -> next = NULL; temp -> item = element; } else { node *temp = new node; temp -> item = element; temp -> prev = tail; tail -> next = temp; temp -> next = NULL; tail = temp; } } int dll::Dequeue() { if(isEmpty()) { exit(1);//edw prepei na valw kati allo } else { node *temp = new node; int k = head -> item; temp = head; head = head -> next; head -> prev = NULL; delete temp; return k; } } int dll::First() { if(isEmpty()) { exit(1);//edw prepei an valw kati allo } else { int k = head -> item; return k; } } int dll::Last() { if(isEmpty()) { exit(1);//edw prepei na valw kati allo } else { int k = tail -> item; return k; } } void dll::Search(int element) { if(isEmpty()) { exit(1);//edw prepei na valw kati allo } else { int k=1,k2=0; node *temp = new node; temp = tail; do { k++; if(element == temp -> item) { cout<< "To stoixeio vrethike. O arithmos twn stoixeivn pou prospelastikan einai :"<< k << endl; k2=1; } temp = temp -> prev; }while(temp != NULL && k2==0); } } void dll::Print() { node *temp = new node; temp = head; do { cout<< temp -> item << " "; temp = temp -> next; }while(temp != NULL); } void dll::Destroy() { node *temp = new node; node *temp2 = new node; node *temp3 = new node; temp = head; do { temp2 = temp -> next; temp3 = temp; delete temp3; temp = temp2; }while(temp != NULL); } void dll::PrintSplit(spliter1* x, spliter2* y) { spliter2 *temp1 = new spliter2; spliter2 *temp2 = new spliter2; temp1 = x; temp2 = y; do { cout<< temp1 -> item << " "; temp1 = temp1 -> next; }while(temp1 != NULL); cout<< endl; do { cout<< temp2 -> item << " "; temp2 = temp2 -> next; }while(temp2 != NULL); } void dll::DestroySplit(spliter1* x, spliter2* y) { spliter1 *temp = new spliter1; spliter2 *temp0 = new spliter2; spliter1 *temp1 = new spliter1; spliter2 *temp2 = new spliter2; temp = x; do { spliter1 *temp3 = new spliter1; temp1 = temp -> next; temp3 = temp; delete temp3; temp = temp1; }while(temp != NULL); temp0 = y; do { spliter2 *temp4 = new spliter2; temp2 = temp0 -> next; temp4 = temp; delete temp4; temp0 = temp2; }while(temp0 != NULL); } int main() { dll q; int ch, temp; while(1) { cout<<endl; cout<<" 1. Enqueue "<<endl; cout<<" 2. Dequeue "<<endl; cout<<" 3. First "<<endl; cout<<" 4. Last "<<endl; cout<<" 5. Search "<<endl; cout<<" 6. Split "<<endl; cout<<" 7. Exit "<<endl; cin>>ch; switch(ch) { case 1 : cout<<" dwse mou to x pou tha mpei sto telos :"; cin>>temp; q.Enqueue(temp); break; case 2 : cout<<" diagrafh kai epistrofh tou 1ou :"; temp = q.Dequeue(); cout<<temp; break; case 3 : cout<<" epistrofh tou 1ou stoixeiou :"; temp = q.First(); cout<<temp; break; case 4 : cout<<" epistrofh tou teleutaiou stoixeiou :"; temp = q.Last(); cout<<temp; break; case 5 : cout<<" dwse x gia anazhthsh :"; cin>>temp; q.Search(temp);//den eimai sigouros meta ti grafw break; case 6 : cout<<" splitting :"; ptr *temp = new ptr; temp = q.Split(); q.PrintSplit(temp -> ptr1, temp -> ptr2); q.DestroySplit(temp -> ptr1, temp -> ptr2); break; case 7 : cout<<" exiting :"; q.Destroy(); system("pause"); return 0; break; } } }
defacer Δημοσ. 1 Δεκεμβρίου 2012 Δημοσ. 1 Δεκεμβρίου 2012 Καλό θα ήταν όταν θέλεις κάποιος να φάει τον ελεύθερο χρόνο του για να σε βοηθήσει να του κάνεις και συ τη ζωή εύκολη για να τον δελεάσεις. Για παράδειγμα, δεν έχω ιδέα τι υποτίθεται ότι πρέπει να κάνει η συνάρτηση στην οποία αναφέρεσαι ενώ εδώ που τα λέμε το "να επιστρέφει 2 Pointer το head1 και το head2" δεν είναι ακριβώς η κορυφή στις τεχνικές περιγραφές. Και σίγουρα δεν πρόκειται να κάνω reverse engineer καμπόσες σελίδες κώδικα με την ελπίδα να το καταλάβω, ούτως ώστε αν τα καταφέρω να κερδίσω τη δυνατότητα να μπορώ να ασχοληθώ ακόμα περισσότερο για να βοηθήσω. http://www.gerv.net/hacking/how-to-ask-good-questions/
Προτεινόμενες αναρτήσεις
Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε
Πρέπει να είστε μέλος για να αφήσετε σχόλιο
Δημιουργία λογαριασμού
Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!
Δημιουργία νέου λογαριασμούΣύνδεση
Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.
Συνδεθείτε τώρα