View difference between Paste ID: 2wUqxCAV and 259qGgwW
SHOW: | | - or go back to the newest paste.
1
#include <stdio.h>
2
#include <string.h>
3
#include <stdlib.h>
4
5
typedef struct _node {
6
	int data;
7
	struct _node *next;
8
} node;
9
10
node *addNode(node *head, int num)
11
{
12
	node * el = head;
13
	node * n = (node*) malloc(sizeof(node));
14
	n->next = NULL;
15
	n->data = num;
16
	if (!head)
17
	{
18
		return n;
19
	}
20
	while (el->next)
21
		el = el->next;
22
	el->next = n;
23
	return head;
24
}
25
26
void disp(node *head, int a, int b)
27
{
28
	node *l1, *u = NULL, *in = NULL;
29
	l1 = head;
30
	while (l1)
31
	{
32
		if (l1->data < a) printf("%d ", l1->data);
33
		else if (l1->data > b) u = addNode(u, l1->data);
34
		else in = addNode(in, l1->data);
35
		l1 = l1->next;
36
	}
37
	l1 = in;
38
	
39
	while (l1)
40
	{
41
		printf("%d ", l1->data);
42
		l1 = l1->next;
43
	}
44
	l1 = u;
45
	while (l1)
46
	{
47
		printf("%d ", l1->data);
48
		l1 = l1->next;
49
	}
50
}
51
52
53
int main()
54
{
55
	int i, a, b, t;
56
	node *head = NULL, *lower = NULL, *upper = NULL, *in = NULL;
57
58
	printf("input a b:");
59
	scanf("%d %d", &a, &b);
60
	printf("input L: ");
61
	do {
62
		scanf("%d", &t);
63
		head = addNode(head, t);
64
	} while (t != 0);
65
66
	disp(head, a, b);
67
68
	_getch();
69
	return 0;
70
}