# Algorithm

Page 1 of 1

## 8 Replies - 1597 Views - Last Post: 22 January 2009 - 01:45 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=82262&amp;s=8c80892405a56253526b60041a294cd6&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jacob22

Reputation: 0
• Posts: 1
• Joined: 22-January 09

# Algorithm

Posted 22 January 2009 - 12:46 PM

Design and implement an algorithm that is given as input an integer value k≥0 and a list of k numbers N₁, N₂… Nĸ. Your algorithm should reverse the order of the numbers in the list. That is, if the original list contained:
N₁=5, N₂=13, N₃=8, N₄=27, N₅=10 (K=5)
Then when your algorithm has completed, the value stored in the list will be
N₁=10, N₂=27, N₃=8, N₄=13, N₅=5

```Input k,
Input N₁, N₂…..Nĸ
K≥0
Set index = 1
While index ≤ k
Set index = Nĸ- index+1
Set index = index +1
Print X₁, X₂…….Xn
stop

```

This post has been edited by jacob22: 22 January 2009 - 01:31 PM

Is This A Good Question/Topic? 0

## Replies To: Algorithm

### #2 Locke

• Sarcasm Extraordinaire!

Reputation: 550
• Posts: 5,624
• Joined: 20-March 08

## Re: Algorithm

Posted 22 January 2009 - 12:49 PM

[rules][/rules]

However, I'm sure if you search the site, you'll find something resembling reverse array...

This post has been edited by Locke37: 22 January 2009 - 12:49 PM

### #3 markhazlett9

• Coding is a lifestyle

Reputation: 61
• Posts: 1,666
• Joined: 12-July 08

## Re: Algorithm

Posted 22 January 2009 - 12:49 PM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

```Your code Here
```

Thank you for helping us helping you.

### #4 mostyfriedman

• The Algorithmi

Reputation: 729
• Posts: 4,473
• Joined: 24-October 08

## Re: Algorithm

Posted 22 January 2009 - 12:52 PM

hint: use arrays

### #5 Gloin

• Expert Schmexpert...

Reputation: 235
• Posts: 4,489
• Joined: 04-August 08

## Re: Algorithm

Posted 22 January 2009 - 12:53 PM

Why would the method take the list-length as argument? Most datastructures have a method to determine its size/length anyways.

### #6 BigAnt

• May Your Swords Stay Sharp

Reputation: 102
• Posts: 2,392
• Joined: 16-August 08

## Re: Algorithm

Posted 22 January 2009 - 01:35 PM

Just loop through the list backwards copying each elements into a new list of the same size.

Does list mean that it we be a object list, or an array?

### #7 melan

Reputation: 0
• Posts: 3
• Joined: 25-September 07

## Re: Algorithm

Posted 22 January 2009 - 01:37 PM

...

This post has been edited by melan: 22 January 2009 - 01:40 PM

### #8 markhazlett9

• Coding is a lifestyle

Reputation: 61
• Posts: 1,666
• Joined: 12-July 08

## Re: Algorithm

Posted 22 January 2009 - 01:44 PM

I don't understand what your errors are. Please post errors and a decent effort for code. Thanks

### #9 LaFayette

• D.I.C Regular

Reputation: 43
• Posts: 326
• Joined: 24-November 08

## Re: Algorithm

Posted 22 January 2009 - 01:45 PM

Another possiblity is to iterate over the k/2 first element of the list and exchanging these values with the corresponding values on the other side, so to speak.