Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added three files . #106

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions DSA/circular linklist
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
class Node:
def __init__(self,data):
self.data = data;
self.next = None;

class CreateList:
#Declaring head and tail pointer as null.
def __init__(self):
self.head = Node(None);
self.tail = Node(None);
self.head.next = self.tail;
self.tail.next = self.head;

#This function will add the new node at the end of the list.
def add(self,data):
newNode = Node(data);
#Checks if the list is empty.
if self.head.data is None:
#If list is empty, both head and tail would point to new node.
self.head = newNode;
self.tail = newNode;
newNode.next = self.head;
else:
#tail will point to new node.
self.tail.next = newNode;
#New node will become new tail.
self.tail = newNode;
#Since, it is circular linked list tail will point to head.
self.tail.next = self.head;

#Displays all the nodes in the list
def display(self):
current = self.head;
if self.head is None:
print("List is empty");
return;
else:
print("Nodes of the circular linked list: ");
#Prints each node by incrementing pointer.
print(current.data),
while(current.next != self.head):
current = current.next;
print(current.data),


class CircularLinkedList:
cl = CreateList();
#Adds data to the list
cl.add(1);
cl.add(2);
cl.add(3);
cl.add(4);
#Displays all the nodes present in the list
cl.display();
28 changes: 28 additions & 0 deletions Recursion/lucky_Numbers using recursion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#User function Template for python3


class Solution:
def lucky(self,n,i):
if(n%i==0):
return False
elif(n<i):
return True
p=n-(n//i)
return self.lucky(p,i+1)
def isLucky(self, n):
#RETURN True OR False
return self.lucky(n,2)

# Driver Code Starts
if __name__ == '__main__':
t=int(input())

for tcs in range(t):
n=int(input())
obj = Solution()
if obj.isLucky(n):
print(1)
else:
print(0)

# } Driver Code Ends
16 changes: 16 additions & 0 deletions Recursion/subsequence_recursion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def get_all_subsequence(n,output,i):
if (i==len(n)):
if (len(output)!=0):
print(output)
else:
# exclude first character
get_all_subsequence(n,output,i+1)

# include first character
output+=n[i]
get_all_subsequence(n,output,i+1)
return

n = input()
get_all_subsequence(n,"",0)
print(n[0])