File tree 2 files changed +48
-0
lines changed
2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ // https://practice.geeksforgeeks.org/problems/left-index-1587115620/1/?track=SPCF-Searching&batchId=154
2
+ int leftIndex (int N, int arr[], int X){
3
+ if (arr[N-1 ] < X)
4
+ return -1 ;
5
+
6
+ for (int i =0 ; i < N; i++)
7
+ {
8
+ if (arr[i] == X)
9
+ return i;
10
+ }
11
+ return -1 ;
12
+ }
Original file line number Diff line number Diff line change
1
+ // https://practice.geeksforgeeks.org/problems/linked-list-insertion-1587115620/1/?track=PC-W5-LL&batchId=154/*Structure of the linked list node is as
2
+ struct Node {
3
+ int data;
4
+ struct Node * next;
5
+ Node (int x) {
6
+ data = x;
7
+ next = NULL ;
8
+ }
9
+ }; */
10
+
11
+ // function inserts the data in front of the list
12
+ Node *insertAtBegining (Node *head, int newData) {
13
+ Node *new_node = new Node (newData);
14
+ if (head == NULL )
15
+ return new_node;
16
+ else
17
+ {
18
+ new_node ->next = head;
19
+ return new_node;
20
+ }
21
+ }
22
+
23
+
24
+ // function appends the data at the end of the list
25
+ Node *insertAtEnd (Node *head, int newData) {
26
+ Node *new_node = new Node (newData);
27
+ if (head == NULL )
28
+ return new_node;
29
+
30
+ Node *current = head;
31
+ while (current->next != NULL )
32
+ current = current->next ;
33
+
34
+ current->next = new_node;
35
+ return head;
36
+ }
You can’t perform that action at this time.
0 commit comments