Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- struct cvor {
- int podatak;
- cvor *next;
- };
- cvor *glava;
- void upis(int a, int &n) {
- n++;
- cvor *novi = new cvor;
- novi->podatak = a;
- novi->next = NULL;
- if (glava == NULL) {
- glava = novi;
- }
- else {
- cvor*trenutni;
- trenutni = glava;
- while (trenutni->next != NULL) {
- trenutni = trenutni->next;
- }
- trenutni->next = novi;
- }
- cvor*trenutni;
- trenutni = glava;
- for (int i = 0; i < n - 1; i++) {
- for (int j = 0; j < n - i - 1; j++) {
- if (trenutni->podatak > trenutni->next->podatak) {
- swap(trenutni->podatak, trenutni->next->podatak);
- }
- }
- }
- }
- void ispis() {
- cvor *trenutni;
- trenutni = glava;
- while(trenutni != NULL) {
- cout << trenutni->podatak<< " ";
- trenutni = trenutni->next;
- }
- }
- void brisi() {
- cvor*trenutni;
- while (glava != NULL) {
- trenutni = glava;
- glava = glava->next;
- delete trenutni;
- }
- }
- void izbroj() {
- cvor *trenutni;
- trenutni = glava;
- //while(trenutni != NULL) {
- for (int i = 0; i < 10; i++) {
- trenutni = trenutni->next;
- }
- }
- int main() {
- int n = 0;
- cout << "Upis " << endl;
- upis(5, n);
- upis(12, n);
- upis(3, n);
- upis(1, n);
- ispis();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement