Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- typedef struct _node {
- int data;
- struct _node *next;
- } node;
- node *addNode(node *head, int num)
- {
- node * el = head;
- node * n = (node*) malloc(sizeof(node));
- n->next = NULL;
- n->data = num;
- if (!head)
- {
- return n;
- }
- while (el->next)
- el = el->next;
- el->next = n;
- return head;
- }
- void disp(node *head, int a, int b)
- {
- node *l1, *u = NULL, *in = NULL;
- l1 = head;
- while (l1)
- {
- if (l1->data < a) printf("%d ", l1->data);
- else if (l1->data > b) u = addNode(u, l1->data);
- else in = addNode(in, l1->data);
- l1 = l1->next;
- }
- l1 = in;
- while (l1)
- {
- printf("%d ", l1->data);
- l1 = l1->next;
- }
- l1 = u;
- while (l1)
- {
- printf("%d ", l1->data);
- l1 = l1->next;
- }
- }
- int main()
- {
- int i, a, b, t;
- node *head = NULL, *lower = NULL, *upper = NULL, *in = NULL;
- printf("input a b:");
- scanf("%d %d", &a, &b);
- printf("input L: ");
- do {
- scanf("%d", &t);
- head = addNode(head, t);
- } while (t != 0);
- disp(head, a, b);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment