#include #include typedef struct elem { int v; struct elem* next; } Element; Element* Init() { return NULL; } Element* Insert(Element* list, int value) { if(list == NULL) { // Ako je lista prazna list = (Element*) malloc (sizeof(Element)); list->v = value; list->next = NULL; return list; } if(list->v > value) { // Dodavanje na pocetak liste Element* n = (Element* ) malloc(sizeof(Element)); n->v = value; n->next = list; return n; } Element* temp = list; while(temp->next != NULL) { if(temp->next->v > value) break; temp = temp->next; } if(temp->next == NULL) { // Dodavanje na kraj liste temp->next = (Element*) malloc (sizeof(Element)); temp = temp->next; temp->v = value; temp->next = NULL; } else { // Dodavanje u sredinu liste Element* n = (Element*) malloc (sizeof(Element)); n->v = value; n->next = temp->next; temp->next = n; } return list; } void Print(Element* list) { if(list == NULL) { printf("List is empty\n"); return; } Element* t = list; while(t != NULL) { printf("%d\t", t->v); t = t->next; } putchar('\n'); } int main(int argc, char *argv[]) { Element* list = Init(); Print(list); list = Insert(list, 5); list = Insert(list, 8); list = Insert(list, 6); list = Insert(list, 7); list = Insert(list, 10); list = Insert(list, 2); list = Insert(list, 2); list = Insert(list, 14); list = Insert(list, 1); list = Insert(list, 8); Print(list); system("PAUSE"); return 0; }