My issue
not able to give input to a linked list so that i can modify it accordingly
My code
#include <bits/stdc++.h>
using namespace std;
int main()
{
// your code goes here
struct node
{
int data ;
node* next;
node(int val) : data(val), next(nullptr) {}
};
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
node* head = new node(0);
node* curr =head;
int i=0;
while(i<n){
curr->next= new node(arr[i]);
curr=curr->next;
}
curr = head;
head=head->next;
delete(curr);
int cp=0;
node* prev=head;
node* cur=head->next;
while(cur!=NULL && cur->next!=NULL)
{
//if the node is local minima return cp;
if(cur->data < prev->data && cur->data < cur->next->data)
{
cp++;
}
//if the node is local maxima
else if(cur->data > prev->data && cur->data > cur->next->data )
{
cp++;
}
//moving to next set of nodes
prev=cur;
cur=cur->next;
}
return cp;
}
Learning course: Linked Lists
Problem Link: Crits in a Linked List! Practice Problem in - CodeChef