forked from HarshCasper/NeoAlgo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I have solved the issue HarshCasper#1439 in which i have written code in python for Moore Algorithm.
- Loading branch information
1 parent
959dfdf
commit 678c11a
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## This Program Checks the maximum occurence of a number in a array/list | ||
def counting_fun(array): | ||
count_temp = 0 #For storing the occurence of a number | ||
for i in range(0,len(array)): | ||
count_temp = array.count(array[i]) # Counts the occurence | ||
if count_temp > number/2: | ||
print(f"Number occuring more than n/2 is :{array[i]}") ##Prints the number with max occurence | ||
count_temp = "True" | ||
break | ||
if(count_temp != "True"): | ||
print("No Element occuring more than n/2") | ||
|
||
#Read Program from Here -> | ||
number = int(input("Enter Number of values you will enter(eg. 6) : ")) | ||
i=0 | ||
list_1 = [] # List Declaration | ||
print(f"Enter {number} values: ") | ||
for i in range(0, number): | ||
elements = int(input()) | ||
list_1.append(elements) # adding element to the list | ||
|
||
counting_fun(list_1) | ||
|
||
#Go to the line 1 for reading function | ||
|
||
|
||
## Output : | ||
|
||
/* Enter 6 values: | ||
1 | ||
1 | ||
1 | ||
1 | ||
4 | ||
2 | ||
Number occuring more than n/2 is :1 */ | ||
|