এই সমস্যায়, প্রোগ্রামটিকে অবশ্যই প্রদত্ত লিঙ্কযুক্ত তালিকা থেকে বিকল্পগুলি মুদ্রণ করতে হবে যা একটি মুদ্রণ অন্যটিকে ছেড়ে দিচ্ছে এবং একইভাবে পুনরাবৃত্তিমূলক পদ্ধতি ব্যবহার করে৷
পুনরাবৃত্তিমূলক পদ্ধতি হল এমন একটি যা সাধারণত লুপগুলি ব্যবহার করে যা শর্তটি মান 1 বা সত্য না হওয়া পর্যন্ত কার্যকর করা হয়৷
ধরা যাক, তালিকায় 29, 34, 43, 56 এবং 88 নোড রয়েছে এবং আউটপুটের পরিবর্তে 29, 43 এবং 88 এর মতো বিকল্প নোড হবে।

উদাহরণ
Input: 29->34->43->56->88 Output: 29 43 88
পদ্ধতিটি শেষ নোড পর্যন্ত পুরো তালিকাটি অতিক্রম করা। যখন, একটি কাউন্টার ভেরিয়েবল অতিক্রম করার সময় নেওয়া যেতে পারে যা 1 এ বৃদ্ধি করা হয় এবং ব্যবহারকারীর পছন্দের উপর নির্ভর করে কাউন্টারটি জোড় বা বিজোড় হলে মান প্রিন্ট করা হয়। ব্যবহারকারী যদি এটি 0 থেকে প্রদর্শন করতে চান তবে জোড় মান সহ কাউন্টারটি প্রদর্শিত হবে অন্যথায় বিজোড় মান সহ কাউন্টারটি প্রদর্শিত হবে।
নিচের কোডটি প্রদত্ত অ্যালগরিদমের সি বাস্তবায়ন দেখায়।
অ্যালগরিদম
START Step 1 -> create node variable of type structure Declare int data Declare pointer of type node using *next Step 2 -> Declare Function void alternate(struct node* head) Set int count = 0 Loop While (head != NULL) IF count % 2 = 0 Print head->data Set count++ Set head = head->next End Step 3 -> Declare Function void push(struct node** header, int newdata) Create newnode using malloc function Set newnode->data = newdata Set newnode->next = (*header) set (*header) = newnode step 4 -> In Main() create head pointing to first node using struct node* head = NULL Call alternate(head) STOP
উদাহরণ
#include <stdio.h>
#include <stdlib.h>
//creating structure of a node
struct node {
int data;
struct node* next;
};
//function to find and print alternate node
void alternate(struct node* head) {
int count = 0;
while (head != NULL) {
if (count % 2 == 0)
printf(" %d ", head->data);
count++;
head = head->next;
}
}
//pushing element into the list
void push(struct node** header, int newdata) {
struct node* newnode =
(struct node*)malloc(sizeof(struct node));
newnode->data = newdata;
newnode->next = (*header);
(*header) = newnode;
}
int main() {
printf("alternate nodes are :");
struct node* head = NULL;
push(&head, 1); //calling push function to push elements in list
push(&head, 9);
push(&head, 10);
push(&head, 21);
push(&head, 80);
alternate(head);
return 0;
} আউটপুট
যদি আমরা উপরের প্রোগ্রামটি চালাই তবে এটি নিম্নলিখিত আউটপুট তৈরি করবে।
alternate nodes are : 80 10 1