473,508 Members | 2,152 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Silly do - while question

Newbie <ne****@gmail.comwrites:
#include <stdio.h>
#include <string.h>

void Permute(char *Perm,
size_t n,
size_t unchanged)
{
<snip>
/*
All i want here is to continue with rotation above if the first
element of right array is same as that before the rotation takes
place.
I know this is really silly but i just cannot figure it out!
Please Help!!!
*/
The version you posted in comp.programming has the correct loop. Why
change it?

--
Ben.
Aug 2 '08 #1
5 1449
Ben Bacarisse wrote:
Newbie <ne****@gmail.comwrites:
>#include <stdio.h>
#include <string.h>

void Permute(char *Perm,
size_t n,
size_t unchanged)
{
<snip>
>/*
All i want here is to continue with rotation above if the first
element of right array is same as that before the rotation takes
place.
I know this is really silly but i just cannot figure it out!
Please Help!!!
*/

The version you posted in comp.programming has the correct loop. Why
change it?
I have figured out the algorithm after some effort but I don't want to
print duplicated elements in the string.

So an input like "aabcc" should produce only distinct permutations.
Aug 2 '08 #2
Newbie <ne****@gmail.comwrites:
Ben Bacarisse wrote:
>Newbie <ne****@gmail.comwrites:
>>#include <stdio.h>
#include <string.h>

void Permute(char *Perm,
size_t n,
size_t unchanged)
{
<snip>
>>/*
All i want here is to continue with rotation above if the first
element of right array is same as that before the rotation takes
place.
I know this is really silly but i just cannot figure it out!
Please Help!!!
*/

The version you posted in comp.programming has the correct loop. Why
change it?

I have figured out the algorithm after some effort but I don't want to
print duplicated elements in the string.

So an input like "aabcc" should produce only distinct permutations.
Ah, homework?

--
Ben.
Aug 2 '08 #3
Ben Bacarisse wrote:
Newbie <ne****@gmail.comwrites:
>Ben Bacarisse wrote:
>>Newbie <ne****@gmail.comwrites:

#include <stdio.h>
#include <string.h>
....snip..

Ah, homework?

No . Writing a recursive solution is a lot easier(even an iterative
one). In fact i don't need the "rotation" method if duplicate elements
are not a concern.
i know its pretty silly but i just cannot figure it out at this point of
time.

for(outer = unchanged; outer < n; outer++)
{

/*Rotate the array to the right*/
do {
temp = Perm[outer];
for(inner = outer; inner unchanged; inner--){
Perm[inner] = Perm[inner - 1];
}
Perm[unchanged] = temp;

/*Done Rotation*/
}while( temp == Perm[unchanged]);

This is an infinite loop.I guess the while statement should be while (
temp == Perm [outer]).Tried increasing outer(keeping bounds in mind)
inside the do {} part as well but nothing will work when I really need
it to.

Anyways thanks for the reply.

Aug 2 '08 #4
Newbie said:
Ben Bacarisse wrote:
<snip>
>Ah, homework?

No . Writing a recursive solution is a lot easier
Especially when someone else wrote it.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 2 '08 #5
Richard Heathfield wrote:
Newbie said:
>Ben Bacarisse wrote:

<snip>
>>Ah, homework?
No . Writing a recursive solution is a lot easier

Especially when someone else wrote it.
Yes sir. Its your Code. I never claimed it to be mine.

This is only half the solution I am trying to achieve.
If you can help me change this for duplicated strings,
it will suffice.But then it is a question more apt for
comp.lang.programming.Sigh !

void permute(char* v, const int start, const int n)
{
char tmp ;
int i;
int repeat = 0;

if (start == n-1) {
if (v != 0) {
for (i = 0; i < n; i++) {
printf("%c", v[i] );
}
printf("\n");
}
}
else {
for (i = start; i < n; i++) {
tmp = v[i];
v[i] = v[start];
v[start] = tmp;

permute(v, start+1, n);

v[start] = v[i];
v[i] = tmp;
}
}
}

Probably the question was too silly to be answered.
Thank You.

Aug 2 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1879
by: Pjotr Wedersteers | last post by:
This may be a silly question, but I was wondering. If 10 clients fill out a form on my page simultaneaously and hit submit, how does my (Apache2.0.50/PHP4.3.8) server exactly ensure each gets...
4
263
by: Jenny | last post by:
Hi you al I have two very silly question The first one is In vb 6.0 you can add a procedure, sub or function, by clicking add procedure from the tools item on the menuba I cannot seem to find...
4
1172
by: musosdev | last post by:
I think I'm having a dim day and should just go back to bed, but alas, I cant do that.... I'm writing a peice of code to create XHTML compliant documents using System.IO, there's probably an...
6
1230
by: Adam Honek | last post by:
Hi, I've looked over and over and in MSDN 2005 and just can't find what is a really simple answer. How do I select the first value in a combo box to be shown? I tried the .selectedindex -1...
7
1258
by: Matt | last post by:
I've asked this question to some developers that are much more experienced than I, and gotten different answers --- and I can't find anything about it in the documentation. Dim vs. Private as a...
2
1558
by: Willem Voncken | last post by:
Hi guys, might be a silly question, but i'm wondering whether it is even possible to generate access violations when using C#? I'm new at c# programming, but i have some experience with c++....
1
333
by: Pontifex | last post by:
Hi all, Has anyone devised a simple method for passing a string to an external script? For instance, suppose I want to produce a title bar that is very fancy and I don't want my main HTML...
2
1752
by: toton | last post by:
Hi, This is a silly question related to syntax only. I have a template class with template member function, How to write it separately in a file (not translation unit, just want to separate...
4
2075
by: Marcin Kasprzak | last post by:
Hello Guys, Silly question - what is the most elegant way of compiling a code similar to this one? <code> typedef struct a { b_t *b; } a_t; typedef struct b {
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.