lista dwukierunkowa dodawanie i wyswietlanie danych
Ostatnio zmodyfikowano 2017-01-03 00:54
mikewazowski Temat założony przez niniejszego użytkownika |
lista dwukierunkowa dodawanie i wyswietlanie danych » 2017-01-02 22:06:28 jest ktoś w stanie wytlumaczyc mi co w moim kodzie jest nie tak? nie działa dodawanie osob na liste #include <iostream> #include <string> #include <cstdlib> #include <stdio.h> using namespace std; typedef struct DANE { string * imie; } Dane; typedef struct STUDENT Student; struct STUDENT { Dane dane; Student * next; Student * prev; }; Student * stworzelement() { Student * element; string * imie; cout << "podaj imie: "; cin >> imie; imie = new string; element = new Student; element->next = NULL; element->prev = NULL; element->dane.imie = imie; return element; } void dodajkoniec( Student ** head ) { Student * pom, * tmp = stworzelement(); if( * head == NULL ) * head = NULL; else { pom = * head; while( pom->next != NULL ) pom = pom->next; tmp->prev = pom; pom->next = tmp; } } void wyswietl( Student * head ) { Student * tmp; tmp = head; if( tmp == NULL ) cout << "brak elementow"; else { int n = 1; while( tmp != NULL ) { cout << "imie: " << tmp->dane.imie << endl tmp = tmp->next; } } }
int main() { dodajkoniec( & head ); wyswietl( head ); return 0; }
|
|
pekfos |
» 2017-01-02 22:25:28 if( * head == NULL ) * head = NULL; |
No.. ta instrukcja wszystko zmienia. Wszystko poza robieniem czegokolwiek użytecznego. |
|
mikewazowski Temat założony przez niniejszego użytkownika |
» 2017-01-02 22:30:31 poprawione na * head = tmp; ale nadal wywala blad w linijce cin >> imie; "no match for 'operator >>' " |
|
michal11 |
» 2017-01-02 22:40:35 Dlaczego trzymasz stringa przez wskaźnik? |
|
mikewazowski Temat założony przez niniejszego użytkownika |
» 2017-01-02 22:43:38 w sumie trudno stwierdzić czemu ustawiłam 2 razy string * imie; ale po wpisaniu string imie; nadal ten sam problem w cin >> imie; |
|
michal11 |
» 2017-01-02 23:07:04 Zmieniłaś to w funkcji stworzelement czy w strukturze DANE? Wstaw aktualny kod. |
|
mikewazowski Temat założony przez niniejszego użytkownika |
» 2017-01-02 23:09:13 #include <iostream> #include <string> #include <cstdlib> #include <stdio.h> using namespace std; typedef struct DANE { string imie; } Dane; typedef struct STUDENT Student; struct STUDENT { Dane dane; Student * next; Student * prev; }; Student * stworzelement() { Student * element; string imie; cout << "podaj imie: "; cin >> imie; imie = new string; element = new( struct Student ); element->next = NULL; element->prev = NULL; element->dane.imie = imie; return element; } void dodajkoniec( Student ** head ) { Student * pom, * tmp = stworzelement(); if( * head == NULL ) { * head = tmp; cout << "dodano do bazy" << endl; } else { pom = * head; while( pom->next != NULL ) pom = pom->next; tmp->prev = pom; pom->next = tmp; } } void wyswietl( Student * head ) { Student * tmp; tmp = head; if( tmp == NULL ) cout << "brak elementow"; else { int n = 1; while( tmp != NULL ) { cout << "imie: " << tmp->dane.imie << endl tmp = tmp->next; } } }
int main() { dodajkoniec( & head ); wyswietl( head ); return 0; }
|
|
mokrowski |
» 2017-01-03 00:28:06 #include <iostream> #include <string> #include <cstdlib>
#include <cstdio>
using namespace std;
struct Dane { string imie; };
struct Student { Dane dane; Student * next; Student * prev; };
Student * stworzelement() { Student * element; string imie; cout << "podaj imie: "; cin >> imie; element = new Student(); element->next = NULL; element->prev = NULL; element->dane.imie = imie; return element; }
void dodajkoniec( Student ** head ) { Student * pom; Student * tmp = stworzelement(); if( * head == NULL ) { * head = tmp; cout << "dodano do bazy" << endl; } else { pom = * head; while( pom->next != NULL ) { pom = pom->next; } tmp->prev = pom; pom->next = tmp; } }
void wyswietl( Student * head ) { Student * tmp; tmp = head; if( tmp == NULL ) cout << "brak elementow"; else { int n = 1; while( tmp != NULL ) { cout << "imie: " << tmp->dane.imie << endl; tmp = tmp->next; } } }
int main() { Student * head = NULL; dodajkoniec( & head ); wyswietl( head ); return 0; }
|
|
« 1 » 2 |