Algorithm

design and implement an algorithm

Page 1 of 1

8 Replies - 998 Views - Last Post: 22 January 2009 - 01:45 PM Rate Topic: -----

#1 jacob22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • 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

Was This Post Helpful? 0
  • +
  • -

#3 markhazlett9  Icon User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 60
  • View blog
  • 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.

Please post like this:

Your code Here


Thank you for helping us helping you.
Was This Post Helpful? 0
  • +
  • -

#4 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 724
  • View blog
  • Posts: 4,470
  • Joined: 24-October 08

Re: Algorithm

Posted 22 January 2009 - 12:52 PM

hint: use arrays
Was This Post Helpful? 0
  • +
  • -

#5 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#6 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#7 melan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#8 markhazlett9  Icon User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 60
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#9 LaFayette  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1