0% found this document useful (0 votes)
14 views1 page

Import Java.utils.arrays;

The document contains Java code for a class that checks if two strings are anagrams by sorting their characters. It also includes a Python class that sorts a stack so that the maximum element is on top using recursion. The Java main method tests the anagram functionality with the strings 'listen' and 'silent'.

Uploaded by

anjaliyadavp1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

Import Java.utils.arrays;

The document contains Java code for a class that checks if two strings are anagrams by sorting their characters. It also includes a Python class that sorts a stack so that the maximum element is on top using recursion. The Java main method tests the anagram functionality with the strings 'listen' and 'silent'.

Uploaded by

anjaliyadavp1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.utils.

Arrays;

public class Anagrams{


public static boolean areAnagrams(String str1 , String str2 )
{
char [] str1Array = str1.toCharArray();
char [] str2Array = str2.toCharArray();
Arrays.sort(str1Array);
Arrays.sort(str2Array);
return Arrays

public static void main(String [] args)


{
String str1 ="listen" ;
String str2 = "silent" ;
System.out.println(areAnagrams(str1, str2));
}}

class Solution:
# your task is to complete this function
# function sort the s such that top element is max
# funciton should return nothing
# s is a stack
def Sorted(self, s):
# Code here
if len(s) <= 1:
return

top = s.pop()
self.Sorted(s)

self.insert_in_sorted_s(s,top)

def insert_in_sorted_s (self,s, element):


if not s or s[-1] <= element :
s.append(element)
return

top = s.pop()
self.insert_in_sorted_s(s,element )
s.append(top)

You might also like