This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, data=None): | |
self.data = data | |
self.next = None | |
class SinglyLinkedList: | |
def __init__(self): | |
self.head = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insert_at_pos(head, data, position): | |
# edge case: check if pos is 0 | |
new_node = Node(data) | |
if position is 0: | |
new_node.next = head | |
head = new_node | |
return head | |
pos = 0 | |
new_node = Node(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insert_at_end(head, data): | |
new_node = Node(data) | |
current = head | |
while current.next: # traversing till the last node | |
current = current.next | |
# change the next of last node | |
current.next = new_node | |
return head |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# insertion of new node at front of linked list | |
def insert_at_front(head, data): | |
# creating new node to be inserted | |
new_node = Node(data) | |
new_node.next = head # pointing the new node's next to head | |
head = new_node # making the new node as head | |
return head |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, data): | |
self.data = data # assigning the data passed | |
self.next = None # initializing the node as null | |
class LinkedList: | |
def __init__(self): | |
self.head = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, data): | |
self.data = data # assigning the data passed | |
self.next = None # initializing the node as null | |
class LinkedList: | |
def __init__(self): | |
self.head = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, data): | |
self.data = data # assigning the data passed | |
self.next = None # initializing the node as null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PermutationInString { | |
fun checkInclusion(s1:String, s2: String): Boolean { | |
val len1 = s1.length | |
val len2 = s2.length | |
val value = Array(26) {0} | |
if (len2 < len1) return false | |
for (i in 0 until len1) { | |
// filling value array with the frequencies of string 1 | |
value[s1[i] - 'a']++ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
val providers = ServiceLoader.load(DataSourceProvider::class.java, null) | |
val dataSources = providers.map { | |
it.getDataSource(activity) | |
}.toSet() | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface DataSourceProvider { | |
fun getDataSource(context:Context):DataSource | |
} |