Untitled
unknown
plain_text
5 days ago
1.2 kB
6
Indexable
#include <iostream> #include <vector> #include <list> using namespace std; struct List { string id; int data; List* next = nullptr; }; void f(List** x); void stergere(List** a, int nr = 0, int locatie = 0); void scriere(List* a); int main() { List* head = new List(); //ead->data = 10; f(&head); //scriere(head); //cout << head->next->data; f(&head); f(&head); f(&head); f(&head); f(&head); f(&head); // cout << head->next->next->data; scriere(head); stergere(&head, 3, 0); scriere(head); } void scriere(List* a) { List* s; s = a; while (s != nullptr) { cout << s->data << " "; s = s->next; } } void f(List** x) { List* element1 = new List(); cin >> element1->data; List* temp = *x; while (temp->next != nullptr) { temp = temp->next; } temp->next = element1; } void stergere(List* a, int nr = 0, int locatie = 0) { List* h = new List(); h = a; for (int i = 0; i <= nr - 1; i++) { h = h->next; } h = h->next->next; }
Editor is loading...
Leave a Comment