Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 25a4b69

Browse files
authored
Merge pull request #73 from Ishita-Mehta/linked-list-last-occurrence
#62 Last Occurrence(Index) of an Element in Linked List
2 parents c2fac7f + 6ea2782 commit 25a4b69

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import java.util.*;
2+
3+
4+
public class LastOccurrence
5+
{
6+
public static void main(String[] args)
7+
{
8+
LinkedList<String> linkedList = new LinkedList<String>();
9+
10+
linkedList.add("Apple");
11+
linkedList.add("Banana");
12+
linkedList.add("Strawberry");
13+
linkedList.add("Guava");
14+
linkedList.add("Strawberry");
15+
linkedList.add("Mango");
16+
linkedList.add("Banana");
17+
linkedList.add("Papaya");
18+
linkedList.add("Strawberry");
19+
linkedList.add("Kiwi");
20+
linkedList.add("Apple");
21+
22+
System.out.println("Enter the element who's last index is to be returned");
23+
Scanner input = new Scanner(System.in);
24+
String element = input.nextLine();
25+
26+
27+
System.out.println("The linked list: " + linkedList);
28+
29+
System.out.println("Last index of " + element + " " + linkedList.lastIndexOf(element));
30+
}
31+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Last Occurrence(Index) of an Element in Linked List
2+
3+
Given a particular element in a linked list, find the index of its last occurrence.
4+
5+
### Example:
6+
**Linked List**: [Apple, Banana, Strawberry, Guava, Strawberry, Mango, Banana, Papaya, Strawberry, Kiwi, Apple]
7+
**Input** : Apple
8+
9+
**Output:** :
10+
11+
```
12+
Last index of Apple 10
13+
```
14+
15+
16+
17+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /