NachiketN.89
BAN USERString sentence = "This is test";
String[] words = sentence.split(" ");
for(int i = words.length-1 ; i >=0 ; i-- )
{
System.out.print(words[i]);
if(i > 0)
System.out.print(" ");
}
}
boolean isMatch(String src, String pattern)
{
int src_index =0;
int pattern_index = 0;
while(src_index < src.length() && pattern_index < pattern.length())
{
if(pattern.charAt(pattern_index)=='*')
{
if(pattern_index+1 < pattern.length())
{
pattern_index++;
while(src_index < src.length() && src.charAt(src_index)!=pattern.charAt(pattern_index))
{
src_index++;
}
if(src_index >= src.length())
return false;
}
else
{
return true;
}
}
else
{
pattern_index++;
src_index++;
}
}
if(pattern_index < pattern.length() || src_index < src.length())
return false;
else
return true;
}
boolean isMatch(String src, String pattern)
{
int src_index =0;
int pattern_index = 0;
while(src_index < src.length() && pattern_index < pattern.length())
{
if(pattern.charAt(pattern_index)=='*')
{
if(pattern_index+1 < pattern.length())
{
pattern_index++;
while(src_index < src.length() && src.charAt(src_index)!=pattern.charAt(pattern_index))
{
src_index++;
}
if(src_index >= src.length())
return false;
}
else
{
return true;
}
}
else
{
pattern_index++;
src_index++;
}
}
if(pattern_index < pattern.length() || src_index < src.length())
return false;
else
return true;
}
void printAtLevel(Node *treenode, int level)
{
if(treenode==NULL)
return;
if(level==1)
{
printf(" %d ",treenode->data);
}
else if(level > 0)
{
printAtLevel(treenode->right, level-1);
printAtLevel(treenode->left, level-1);
}
}
You are relying on the fact that sum of characters will be same. Which is true for strings of type abc = cab.
What if we have a string bd which also has sum equal to abc?
Suppose I have a program that does the following steps
- NachiketN.89 February 18, 20141. Read a file
2. Read data from a database
3. Compute some values from the info in the file received and the data
4. display something on the screen
When this is realized into code, its a program. When the program is executed, an image of it is created (with some resources such as file handle, etc.) and loaded into main memory and scheduled to run on the processor. Now its a process. Single program be used to instantiate multiple processes.
If we look closely, we can perform steps 1 and 2 independently, then 3rd and then 4th. Do we really need to wait for 1 to finish before beginning 2? To make things work parallel, we can run 1 and 2 parallel in smaller partitions of the process. This partition of the process, which has some resources inherited and its own context within the process is a thread. Threads are lighter weight and help improve throughput since we don't need to wait for executing independent tasks even within a process.