Today I wrote MS written test. There were 3 questions. 10 marks each.
1. Write a program to output all elements of a binary tree while doing a Breadth First traversal through it.
2.Write a method to combine two two sorted linked list into one in sorted form with out usingĀ temporary Node.
void sort(Node* list1,Node* list2)
3.There are set of coins of {50,25,10,5,1} paise in a box.Write a program to find the number of ways a 1 rupee can be created by grouping the paise.
9,248 Views |
This forum sucks to the core. What’s the point in setting up a forum and having a fictitious Ravi’s statement when the forum is not upto the standard.
Answer for 2:
merge the two linked list directly
and sort the combined linked list
This code is written in C#. Again performance and error handling is not given a thought while writting this code. You can optimize it to level you want.
class CoinGames
{
static int _NoofWays = 0;
static void Main(string[] args)
{
int[] Coins = new int[] { 50, 25, 75, 15, 10 };
// iterate through increasing set of numbers
for (int i = 1; i
int a[] = {50,25,75,15,10};
int nSize = 5 // Array size
int nWays= 0; //no of ways
int nWordCount = 1;
while(nWordCount
Hi,
I wrote a program for this..
Not sure if someone can come up with a more efficient version!..
public string permCoins()
{
string s = “”;
int[] coins = new int[] {50, 25, 75, 15, 10};
for (int combCount = 2; combCount
2.Write a method to combine two two sorted linked list into one in sorted form with out using temporary Node.
NODE MergedSortedList(NODE node1, NODE node2)
{
if(NULL == node1 ) return node2;
if(NULL == node2) return node1;
if(node1->info info)
node1->next = MergedSortedList(node1->next,node2);
return node1;
}
else if(node1->info > node2->info)
node1->next = MergedSortedList(node1,node2->next);
return node2;
}
else if(node1->info == node2->info)
node1->next= node2;
node2->next= MergedSortedList(node1->next,node2->next);
return node1;
}
}
Leave an Answer/Comment