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 <string.h>
- typedef struct cvor* PCVOR;
- typedef struct cvor {
- int data;
- PCVOR next;
- }CVOR;
- void ubaciNaPocetak(PCVOR* head, int num);
- void ubaciNaKraj(PCVOR* head, int num);
- void izbaciSaPocetka(PCVOR* head);
- void izbaciSaKraja(PCVOR* head);
- void izbaciTrazeniBroj2(PCVOR* head, int find);
- void prebacivanjeNeparnih(PCVOR* head, PCVOR* neparni);
- void ispisiListu(PCVOR head);
- int main(void) {
- PCVOR new = NULL;
- PCVOR neparni = NULL;
- ubaciNaKraj(&new, 1);
- ubaciNaKraj(&new, 2);
- ubaciNaKraj(&new, 3);
- ubaciNaKraj(&new, 4);
- ubaciNaKraj(&new, 5);
- ubaciNaKraj(&new, 6);
- ubaciNaKraj(&new, 7);
- ubaciNaKraj(&new, 8);
- ubaciNaKraj(&new, 9);
- prebacivanjeNeparnih(&new, &neparni);
- ispisiListu(neparni);
- return 0;
- }
- void ubaciNaPocetak(PCVOR* head, int num)
- {
- PCVOR new = malloc(sizeof(CVOR));
- new->data = num;
- new->next = *head;
- *head = new;
- }
- void ubaciNaKraj(PCVOR* head, int num)
- {
- if (*head == NULL) {
- ubaciNaPocetak(head, num);
- return;
- }
- PCVOR new = malloc(sizeof(CVOR));
- new->next = NULL;
- new->data = num;
- PCVOR pom = *head;
- while (pom->next != NULL) {
- pom = pom->next;
- }
- pom->next = new;
- }
- void izbaciSaPocetka(PCVOR* head)
- {
- if (*head == NULL) {
- printf("GRESKA/LISTA JE PRAZNA!\n");
- return;
- }
- PCVOR pom = *head;
- *head = pom->next;
- free(pom);
- }
- void izbaciSaKraja(PCVOR* head)
- {
- if (*head == NULL) {
- printf("GRESKA/LISTA JE PRAZNA!\n");
- return;
- }
- PCVOR temp = *head;
- PCVOR temp_next = temp->next;
- if (temp->next == NULL) {
- izbaciSaPocetka(head);
- return;
- }
- while (temp_next->next != NULL) {
- temp = temp_next;
- temp_next=temp_next->next;
- }
- temp->next = NULL;
- free(temp_next);
- }
- void izbaciTrazeniBroj(PCVOR* head, int find)
- {
- }
- void ispisiListu(PCVOR head)
- {
- if (head == NULL) {
- printf("GRESKA/LISTA JE PRAZNA!");
- return;
- }
- printf("Lista: ");
- while (head != NULL) {
- printf("%3d%3", head->data);
- head = head->next;
- }
- printf("\n");
- }
- void izbaciTrazeniBroj2(PCVOR* head, int find) {
- if (*head == NULL) {
- printf("GRESKA/LISTA JE PRAZNA!");
- return;
- }
- PCVOR temp = *head;
- PCVOR temp_next = temp->next;
- if (temp->data == find) {
- izbaciSaPocetka(head);
- return;
- }
- while (temp_next->data != find) {
- temp = temp_next;
- temp_next = temp_next->next;
- }
- if (temp_next->next == NULL) {
- izbaciSaKraja(head);
- return;
- }
- PCVOR delete = temp_next;
- temp_next = temp_next->next;
- temp->next = temp_next;
- free(delete);
- }
- void prebacivanjeNeparnih(PCVOR* head, PCVOR* neparni)
- {
- PCVOR org = *head;
- while (org != NULL) {
- if (org->data % 2 != 0) {
- ubaciNaKraj(neparni, org->data);
- }
- org = org->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement