a.c.a.b Δημοσ. 4 Ιουνίου 2015 Δημοσ. 4 Ιουνίου 2015 Καλησπέρα! Κανω μια ασκηση στις δομες κ την παραδιδω σε λιγο (πριν τις 12 ) αλλα δεν τα παω κ τοσο καλά κ δεν ξερω αν προλάβω. Όποιος εχει την καλη διαθεση να ριξει μια ματια μηπως μπορει να βοηθησει-εξηγησει θα το υπερεκτιμούσα ! Ειλικρινα ειμαι διατεθειμένη αν κάποιος μπορει να συμπληρωσει το κωδικα κ να μου εξηγησει λιγο πως κ τι εκανε να του κάνω καταθεση με paypal ενα συμβολικο ποσό για ευχαριστω. Δεν την παλευω αλλο!:Ρ Πρεπει να γραψω τις συναρτησεις που εξηγουν τα σχολια στις κενες αγκυλες. #include <stdio.h> #include <malloc.h> struct node { int i; struct node *next; }; struct node * insert(struct node * head, int i) { struct node *temp; temp = (struct node *)malloc(sizeof(struct node)); temp->i = i; temp->next = head; return temp; } /* diagrafei to stoixeio me thesh pos apo thn list. epistrefei to (isws neo) head */ struct node *rmv(struct node * head, int pos) { int i; if (head == NULL) return NULL; if (pos == 0) { struct node *temp = head->next; free(head); return temp; } struct node *prev = head; for (i = 0; i < pos-1; i++) { if (prev->next == NULL) break; prev = prev->next; } if (prev->next == NULL) return head; struct node *temp = prev->next; prev->next = temp->next; free(temp); return head; } /* Typwnei ta periexomena ths listas */ void printList(struct node *head) { struct node *temp; for (temp = head; temp != NULL; temp = temp->next) printf("%d\n", temp->i); } /* epistrefei thn thesh sthn lista tou stoixiou me timh i , an yparxei alliws epistrefei -1*/ int find(struct node * head, int i) { int pos = 0; struct node *temp; for (temp = head; temp != NULL && temp->i != i; temp = temp->next) pos++; if (temp == NULL) return -1; return pos; } /* epistrefei thn timh tou stoixeiou sthn thesh pos, an yparxei h thesh alliws -1 */ int get(struct node * head, int pos) { int i; struct node *temp = head; for (i = 0; i < pos; i++) { if (temp == NULL) break; temp = temp->next; } if (temp == NULL) return -1; return temp->i; } /* Diaforetikh ekdosh ths insert pou eisagagei ta stoixeia sthn lista me ayksanousa seira */ struct node * insertSorted(struct node * head, int i) { } /* Diaforetikh ekdosh ths remove pou afairei stoixia me bash thn timh tous. Dhladh tha afairesei ton kombo (Struct node) apo thn lista pou h timh pou exei apothikeusei einai ish me i (parametros ths synarthshs) */ struct node *r mvValue(struct node * head, int i) { } /* H synarthsh ayth prepei na spaei thn lista se 2 kommatia. to prwto tha exei to idio head kai to 2o (kainourgio head) tha epistrefetai apo thn synarthsh. Ta stoixeia me zygh thesh (0, 2, 4..) tha menoun sthn arxikh lista. Ta stoixeia me monh thesh tha mpainoun sthn kainourgia */ struct node *split(struct node* head) { } /* H synarthsh auth pairnei 2 ksexwristes listes kai tis ennwnei me tropo ANAPODO apo auton ths split epistrefei to head ths (neas?) listas */ struct node *merge(struct node* head1, struct node* head2) { } int main() { struct node *head = NULL; int pos; head = insert(head, 1); head = insert(head, 2); head = insert(head, 3); head = insert(head, 4); pos = find(head, 3); printf("%d\n", pos); head = rmv(head, pos); pos = find(head, 3); printf("%d\n", pos); for (pos = 0; pos < 4; pos++) printf("%d ", get(head, pos)); printf("\n"); }
lion2486 Δημοσ. 4 Ιουνίου 2015 Δημοσ. 4 Ιουνίου 2015 /* Diaforetikh ekdosh ths insert pou eisagagei ta stoixeia sthn lista me ayksanousa seira */ struct node * insertSorted(struct node * head, int i) { //δέσμευσε χώρο για τον νέο κόμβο //έλεγξε αν το πρώτο στοιχείο υπάρχει και είναι μεγαλύτερο //βάλε το νέο στοιχείο στην αρχή (όπως πριν) //αλλιώς βρες το πρώτο μεγαλύτερο στοιχείο (και κράτα το προηγούμενο) //βάλτο στη θέση που βρίκες (συνδέοντας πάλι τη λίστα, δλδ μετά το προηγούμενο και πριν το επόμενο) } /* Diaforetikh ekdosh ths remove pou afairei stoixia me bash thn timh tous. Dhladh tha afairesei ton kombo (Struct node) apo thn lista pou h timh pou exei apothikeusei einai ish me i (parametros ths synarthshs) */ struct node *r mvValue(struct node * head, int i) { //προσπέλασε όλους τους κόμβους (δλδ μέχρι να βρεις ->next == NULL) //αν το στοιχείο είναι ίσο με i, διέγραψέ το είτε επιτόπου, είτε χρησιμοποίηση την ήδη υπάρχον συνάρτηση και δώστης τη θέση } /* H synarthsh ayth prepei na spaei thn lista se 2 kommatia. to prwto tha exei to idio head kai to 2o (kainourgio head) tha epistrefetai apo thn synarthsh. Ta stoixeia me zygh thesh (0, 2, 4..) tha menoun sthn arxikh lista. Ta stoixeia me monh thesh tha mpainoun sthn kainourgia */ struct node *split(struct node* head) { //δέσμευσε ένα δείκτη σε κόμβο //ανα δύο, κάνε εισαγωγή και διαγραφή από την αρχική } /* H synarthsh auth pairnei 2 ksexwristes listes kai tis ennwnei me tropo ANAPODO apo auton ths split epistrefei to head ths (neas?) listas */ struct node *merge(struct node* head1, struct node* head2) { //δέσμευσε ένα δείκτη σε κόμβο //άρχισε τις εισαγωγές ανα ένα στοιχείο } Οι συμβουλές είναι ενδεικτικές και όχι οι αποδοτικότερες. Στο τελευταίο ερώτημα δεν διευκρινίζεται αν οι δύο λίστες μένουν ανέπαφες ή καταστρέφονται. Πιστεύω μπορείς να κάνεις κάτι παραπάνω τώρα.. 1
a.c.a.b Δημοσ. 5 Ιουνίου 2015 Μέλος Δημοσ. 5 Ιουνίου 2015 Σε ευχαριστώ πάρα πολύ! Τελικα δεν προλαβα να τη καταθεσω(=κοπηκα) :/ γιατι μου επεσε το ιντερνετ χτες. Τουλαχιστον όμως ψιλοκαταλαβα τι να γραψω. (Αν θες πμ για paypal. )
Προτεινόμενες αναρτήσεις
Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε
Πρέπει να είστε μέλος για να αφήσετε σχόλιο
Δημιουργία λογαριασμού
Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!
Δημιουργία νέου λογαριασμούΣύνδεση
Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.
Συνδεθείτε τώρα