A little challenge: "Reverse a string"

  • (6 Pages)
  • +
  • « First
  • 3
  • 4
  • 5
  • 6

86 Replies - 38822 Views - Last Post: 27 August 2013 - 02:43 PM

#61 Donanza  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-April 12

Re: A little challenge: "Reverse a string"

Posted 24 April 2012 - 12:02 PM

View Postjjl, on 23 April 2012 - 09:10 PM, said:

Quote

Here is my solution:

Your using a string on line #10

I meant help with the palindrome didn't want to take part!
Anyway i found the palindrome now :)
Was This Post Helpful? 0
  • +
  • -

#62 MrCoder777  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-August 12

Re: A little challenge: "Reverse a string"

Posted 24 August 2012 - 06:17 AM

I can do this by using linked lists. Is that allowed?
Was This Post Helpful? 0
  • +
  • -

#63 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: A little challenge: "Reverse a string"

Posted 24 August 2012 - 12:45 PM

how do you plan to on using a linked list without pointers?
Was This Post Helpful? 0
  • +
  • -

#64 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3457
  • View blog
  • Posts: 10,665
  • Joined: 05-May 12

Re: A little challenge: "Reverse a string"

Posted 24 August 2012 - 11:09 PM

Linked list without pointers... Old school style. Or at least my father tells me that they used to do linked lists like this with arrays. But unfortunately it uses arrays which will disqualify it for this challenge:
Spoiler

This post has been edited by jimblumberg: 25 August 2012 - 01:54 AM
Reason for edit:: Added spoiler tags

Was This Post Helpful? 0
  • +
  • -

#65 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: A little challenge: "Reverse a string"

Posted 25 August 2012 - 01:11 PM

so basically it uses its own allocator with a fixed amount of memory. wouldn't pointers still be slightly more efficient because you wouldn't have to waste the cycles adding the index and the base pointer? just a conjecture, maybe it wouldn't work.
Was This Post Helpful? 0
  • +
  • -

#66 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3457
  • View blog
  • Posts: 10,665
  • Joined: 05-May 12

Re: A little challenge: "Reverse a string"

Posted 25 August 2012 - 03:27 PM

I think it really depends on the machine and how the compiler generates the code, but in general, I think the pointer will win out by having one less operation.

Anyway, thanks to jimblumberg for moving the code into spoiler tags. When I originally posted the code, I deliberately did not put the code in spoiler tags because I was thinking that by implementing Append(), rather than an InsertAtFront(), I was avoiding any hint of trying to solve the challenge listed here. An insert at front would then let you get the reversed string by traversing the list from head to tail and get the string in reverse order. With append, I now realize that you can recursively traverse the list and display the contents in reverse order. But still, this is a no-go since it uses an array.

This post has been edited by Skydiver: 25 August 2012 - 03:28 PM

Was This Post Helpful? 0
  • +
  • -

#67 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: A little challenge: "Reverse a string"

Posted 26 August 2012 - 09:19 PM

I guess I'll try a linked list solution. The rules say you can't use "pointers", I'm not sure if that includes references or not, but here's my linked list solution using temporary references and polymorphism
Spoiler

This post has been edited by jjl: 27 August 2012 - 10:36 PM
Reason for edit:: Added spoiler tags

Was This Post Helpful? 0
  • +
  • -

#68 uzumakinaruto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 29-September 12

Re: A little challenge: "Reverse a string"

Posted 26 November 2012 - 11:07 AM

Spoiler

This post has been edited by ishkabible: 26 November 2012 - 11:39 AM

Was This Post Helpful? 0
  • +
  • -

#69 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: A little challenge: "Reverse a string"

Posted 26 November 2012 - 11:39 AM

post code in code tags in spoiler tags please. not separate.
Was This Post Helpful? 0
  • +
  • -

#70 graycode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-November 12

Re: A little challenge: "Reverse a string"

Posted 27 November 2012 - 07:59 PM

i use array for this in C.
but i don't know if this code runs. But hope this helps.
and please inform me if it won't run.
Spoiler

This post has been edited by GunnerInc: 27 November 2012 - 08:01 PM
Reason for edit:: Added spoiler tags

Was This Post Helpful? 0
  • +
  • -

#71 uzumakinaruto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 29-September 12

Re: A little challenge: "Reverse a string"

Posted 27 November 2012 - 09:44 PM

ive used swapping

Spoiler


please let me know if m wrong smwhere
Was This Post Helpful? 0
  • +
  • -

#72 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: A little challenge: "Reverse a string"

Posted 28 November 2012 - 12:41 AM

Yes, it is wrong. You have to reverse it, not sort it. And everywhere you run your loop from i = 0 to i = l. That is wrong, since you can only access the array upto l-1. So, that is another problem.

EDIT : My bad, I read it wrong.

This post has been edited by aresh: 28 November 2012 - 12:56 AM

Was This Post Helpful? 0
  • +
  • -

#73 uzumakinaruto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 29-September 12

Re: A little challenge: "Reverse a string"

Posted 28 November 2012 - 12:47 AM

but it does reverse the string.
Was This Post Helpful? 0
  • +
  • -

#74 uzumakinaruto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 29-September 12

Re: A little challenge: "Reverse a string"

Posted 28 November 2012 - 12:54 AM

View Postaresh, on 28 November 2012 - 12:41 AM, said:

Yes, it is wrong. You have to reverse it, not sort it.


ok so reversing code isnt basically done by swapping which i just did?
Was This Post Helpful? 0
  • +
  • -

#75 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: A little challenge: "Reverse a string"

Posted 28 November 2012 - 12:58 AM

My bad, I read it wrong and thought you were doing bubble sort. Still, the error I mentioned is there. Also,

Quote

How would you reverse a string without using, pointers, arrays, or c-strings.

But, you have not followed these rules.
Was This Post Helpful? 0
  • +
  • -

  • (6 Pages)
  • +
  • « First
  • 3
  • 4
  • 5
  • 6