Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include < stdlib.h>
- typedef int list_item;
- typedef struct list {
- int data;
- struct list* next;
- }list;
- struct list* head = NULL, * pos;
- int isEmpty(list* head) {
- return (head == NULL) ? 1 : 0;
- }
- struct list* addNode(int num)
- {
- struct list *node = (list*)malloc(sizeof(list));
- node-> data = num;
- node->next = NULL;
- if (isEmpty(head))
- {
- head = node;
- head->next = NULL;
- pos = head;
- }
- else {
- pos->next = node;
- pos = pos->next;
- pos->next = head;
- }
- }
- void display()
- {
- struct list* current;
- if (isEmpty(head))
- {
- printf("List is empty");
- }
- else {
- current = head;
- do {
- printf("%d", current->data);
- current = current->next;
- } while (current != head);
- printf("\n");
- }
- }
- struct list* bigger(list* head)
- {
- int max = head->data;
- int beforeMax = head->data;
- while (head != NULL)
- {
- if (head->data > max)
- {
- max = head->data;
- }
- else if (head->data < max && head->data > beforeMax)
- {
- beforeMax = head->data;
- }
- head = head->next;
- }
- return beforeMax;
- }
- void main()
- {
- list* node = head;
- int num, len, i;
- do {
- printf("\nHow many numbers you want in the list ? ");
- scanf_s("%d", &len);
- if (len <= 0)printf("List must have more numbers than 0");
- } while (len <= 0);
- printf("\nPlease enter %d numbers", len);
- for (i = 0; i < len; i++)
- {
- scanf_s("%d", &num);
- addNode(num);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement