Your post was moved to Homework Help. Is this homework?I am trying to solve with flow chart but after arrow I have no idea how to processed next steps.
No that is not homework question. I am just improving my programming skills. I made it my own specification and I am trying to make flow chart now but I am struggling I have no idea how to go for next step as mention in flow chartYour post was moved to Homework Help. Is this homework?
Are you familiar with awk associative arrays or Perl hashes?No that is not homework question. I am just improving my programming skills.
I am totally agree with you that's why I am not writing code directly as you can see I am trying to make flow chart firstAs always, the place to start is to think about the problem and try out some approaches in your head before doing anything else. You haven't done that and that's why you are stuck again. A pencil and paper is your first tool to use.
No I am not familiar with thatAre you familiar with awk associative arrays or Perl hashes?
Here's a link to Perl code that will do it. Don't look at it until you've tried on your own.No I am not familiar with that
That method is very cumbersome and does not address many of the problems I pointed out. Can you think of a better way? Note: this is why we think, then write on paper before spending lots of time flowing and coding..I tried manually in following way
I don't know if I am on the right track so just spending more time with paper and pencil. can you give manual idea as I was trying in post #8 ?Here's a link to Perl code that will do it. Don't look at it until you've tried on your own.[/URL]
look at post 8 I though one possible way to solve problemThat method is very cumbersome and does not address many of the problems I pointed out. Can you think of a better way?
In the simplest case, you could use the number as an index into an array and increment that array location each time you saw that number. This won't be efficient for large numbers. In that case, you could have an array of pointers that are only initialized each time a unique number is found.can you give manual idea as I was trying in post #8 ?
This is a good illustration of why part of your initial design must include any restrictions on input values. It would be pointless to implements pointers, dynamic memory allocation and all of that if you are only needing the numbers from 1 to 10 for example. A simple array would suffice for that. But if you need to handle a large range of values, 1 to 100000 for example, than that simple array probably would not be the best choice.In the simplest case, you could use the number as an index into an array and increment that array location each time you saw that number. This won't be efficient for large numbers. In that case, you could have an array of pointers that are only initialized each time a unique number is found.
You already tested that in the first pass so this test is redundant. That's what I meant by cumbersome.first pass
is 6 == 4 ? if yes then 6 is repeated number and if no then look for second element
...
second pass
is 4 == 6 ? if yes then 6 is repeated number and if no then look for third element
...
That is cumbersome as pointed out.Numbers[ ] = [ 6, 4, 2, 1, 3, 1 ]
first pass
is 6 == 4 ? if yes then 6 is repeated number and if no then look for second element
<snip>
second pass
is 4 == 6 ? if yes then 6 is repeated number and if no then look for third element
<snip>
multiple pass
Numbers[ ] = [ 6, 4, 2, 1, 3, 1 ]That is cumbersome as pointed out.
Think about this: Once you test and don't find a repeat for the first value, "6,"(or any subsequent value tested) why do you ever need to retest it? Once you find that "1" is repeated, do you need to test the "3?" Do you ever need to test the last number in the array?
by Jake Hertz
by Jake Hertz
by Jake Hertz
by Jake Hertz