-
Notifications
You must be signed in to change notification settings - Fork 0
/
73_LinkedList-CodeChallenge.c
71 lines (68 loc) · 1.83 KB
/
73_LinkedList-CodeChallenge.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Write a program that creates a circular linked list and then prints only those
nodes which happen to be in the range 120 to 255. */
-----> this program is incomplete
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
// following is the structure specification for circular linked list
struct clist
{
int data;
struct clist *link;
};
typedef struct clist node; // using typedef keyword to give alias to structure
// following is the definition of the function create()
node * create(node *start)
{
node *temp,*ptr; // ptr will be used to store the address of previous node
char ch;
int num;
do
{
printf("\n\t Enter the value of number : ");
scanf("%d",&num);
temp = (node*) malloc(sizeof(node));
temp->data = num ;
if(start==NULL)
{
start = temp;
ptr = start;
}
else
{
ptr->link = temp;
ptr = ptr->link; // ptr=temp
}
temp->link = start; // assigning address of the first node to the link of the last node
printf("\n\t Do you want to add more nodes (y/n) : ");
fflush(stdin);
scanf("%c",&ch);
} while(ch=='y'||ch=='Y');
return(start);
}
void display(node *start)
{
node *temp;
printf("\n\n Base address Number Link");
printf("\n ===============================");
if (start->data>=120 && start->data<=255) // checking the value of the very first node
printf("\n%10u %10d %10u",start,start->data,start->link);
for(temp=start->link;temp != start;temp=temp->link)
if (temp->data>=120 && temp->data<=255)
printf("\n%10u %10d %10u",temp,temp->data,temp->link);
getch() ;
return;
}
int main()
{
node *start;
int choice,num,data;
char ch;
start = NULL;
system("cls") ;
printf("\n\t\t **** CREATE BLOCK ****\n");
start = create(start);
printf("\n\t\t **** DISPLAY BLOCK ****\n");
display(start);
}
/**** End of the Program**********/