Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- struct nodo {
- int chiave;
- nodo* next;
- nodo(int a = 0, nodo* b = NULL){chiave = a; next = b;}
- };
- nodo* inserisci_in_ordine(int k, nodo* L) {
- if(L == NULL || L->chiave >= k) {
- nodo* newN = new nodo();
- newN->chiave = k;
- newN->next = L;
- return newN;
- }
- else {
- L->next = inserisci_in_ordine(k, L->next);
- return L;
- }
- }
- void stampa(nodo* L) {
- if(L) {
- cout << L->chiave << " ";
- stampa(L->next);
- }
- }
- int main() {
- nodo* L = NULL;
- int k;
- bool exit = false;
- cout << "start" << endl;
- while(!exit) {
- cin >> k;
- if(k == -1)
- exit = true;
- else
- L = inserisci_in_ordine(k, L);
- }
- stampa(L);
- cout << "end" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement