Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<stdio.h>
- #include <stdlib.h>
- #include <time.h>
- struct cnode
- {
- int value;
- struct cnode *next;
- };
- struct cnode *head = NULL;
- ins(int newVal) {
- struct cnode *tmp = head;
- struct cnode *new = (struct cnode*)malloc(sizeof(struct cnode));
- new->value = newVal;
- if (head == NULL) {
- new->next = new;
- head = new;
- return;
- }
- while (tmp->next != head) {
- tmp = tmp->next;
- }
- tmp->next = new;
- new->next = head;
- head = new;
- }
- delay(int millis) {
- clock_t startTime = clock();
- while (clock() < startTime + millis);
- }
- ptN() {
- char cr = 146;
- if (head == NULL) {
- printf("(empty list) %c \n", cr);
- return;
- }
- struct cnode *tmp=head;
- do {
- printf("[%d] ", tmp->value);
- tmp = tmp->next;
- delay(30);
- } while (tmp!=head);
- printf("\n");
- }
- sorta() {
- struct cnode *tmp = head;
- struct cnode *tmp2 = head->next;
- int aux;
- do {
- do {
- if (tmp2->value > tmp->value) {
- aux = tmp->value;
- tmp->value = tmp2->value;
- tmp2->value = aux;
- }
- tmp2 = tmp2->next;
- } while (tmp2 != head);
- tmp = tmp->next;
- } while (tmp != head);
- }
- del() {
- struct cnode *tmp = head;
- struct cnode *dell;
- dell = head;
- while (tmp->next != head) {
- tmp = tmp->next;
- }
- head = head->next;
- tmp->next = head;
- free(dell);
- }
- insR(int val) {
- time_t t;
- srand(time(NULL));
- while (val) {
- val--;
- ins(rand() % 500);
- }
- }
- clearL() {
- if (head == NULL) {
- printf("lista je prazna!\n");
- return;
- }
- struct cnode *tmp = head;
- struct cnode *aux = (struct cnode*)malloc(sizeof(struct cnode));
- while (tmp->next != head) {
- tmp = tmp->next;
- }
- tmp->next = NULL;
- while (head->next!=NULL) {
- aux = head;
- head = head->next;
- free(aux);
- }
- head = NULL;
- }
- main() {
- ins(9);
- ins(5);
- ins(342);
- ins(32);
- ins(46);
- //sorta();
- ptN();
- del();
- ptN();
- ins(55);
- ptN();
- insR(30);
- ptN();
- clearL();
- ptN();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement