File tree Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ struct node
4
+ {
5
+ int data ;
6
+ struct node * next ;
7
+ } * head , * temp ;
8
+ void creatLinkList (int n );
9
+ void display ();
10
+ int main ()
11
+ {
12
+ int n ;
13
+ printf ("enter the number of nodes" );
14
+ scanf ("%d" , & n );
15
+ creatLinkList (n );
16
+ display ();
17
+ }
18
+ void creatLinkList (int n )
19
+ {
20
+ int i , num ;
21
+ struct node * newNode ;
22
+ if (n >= 1 )
23
+ {
24
+ head = (struct node * )malloc (sizeof (struct node ));
25
+ if (head != 0 )
26
+ {
27
+ printf ("enter the data" );
28
+ scanf ("%d" , & num );
29
+ head -> data = num ;
30
+ head -> next = NULL ;
31
+ temp = head ;
32
+
33
+ for (i = 2 ; i <= n ; i ++ )
34
+ {
35
+ newNode = (struct node * )malloc (sizeof (struct node ));
36
+ if (newNode != 0 )
37
+ {
38
+ printf ("enter the data" );
39
+ scanf ("%d" , & num );
40
+ newNode -> data = num ;
41
+ temp -> next = newNode ;
42
+ newNode -> next = NULL ;
43
+ temp = newNode ;
44
+ }
45
+ temp -> next = head ;
46
+ }
47
+ }
48
+ }
49
+ }
50
+ void display ()
51
+ {
52
+ struct node * tmp ;
53
+ tmp = head ;
54
+ printf ("\ndisplay odd element of the Circular Linked List\n" );
55
+ while (tmp -> next != head )
56
+ {
57
+ if (tmp -> data % 2 != 0 )
58
+ {
59
+ printf ("%d\t" , tmp -> data );
60
+ }
61
+ tmp = tmp -> next ;
62
+ }
63
+ if (tmp -> data %2 != 0 )
64
+ {
65
+ printf ("%d" , tmp -> data ); // checking if last element is odd or not
66
+ }
67
+ }
You can’t perform that action at this time.
0 commit comments