Closed Thread
Results 1 to 2 of 2

Thread: Reverse String using Stack.

  1. #1
    nt_virus is offline Newbie
    Join Date
    Feb 2008
    Posts
    12
    Rep Power
    0

    Reverse String using Stack.

    ====Message 1 ====
    hi mate. How to solve this problem.. I think we need to declare two arrays.. Pop of 1st array should be push for 2nd array .. But cant implement it. Please help.

    ====Message 2 ====
    while searching on google. I found this .. Kerry D. Wong » Blog Archive » Three Ways to Reverse a String in C# .. But really cant understand anything

    ====Message 3 ====
    Is this correct.. ?

    [HIGHLIGHT="C#"]Public void pop()
    {
    Console.WriteLine("popped item :" + firstarray[top]);
    For (int i = 0 ; i<array_size ; i++)
    Secondarray[i]=firstarray[top];
    Top--;
    }
    [/HIGHLIGHT]
    I think FOR loop is not needed because overflow and underflow will be check on another function by bool

    [HIGHLIGHT="C#"]Public void pop()
    {
    Console.WriteLine("popped item :" + firstarray[top]);
    Secondarray[i]=firstarray[top];
    Top--;
    }[/HIGHLIGHT]
    Last edited by nt_virus; 02-23-2008 at 08:00 PM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    BackSlash is offline Newbie
    Join Date
    Feb 2008
    Posts
    12
    Rep Power
    0
    I am wondering if you would want somthing like this

    String str = "Hello This Is My String";

    you can use the Split() to split at a char

    it will return a string array and you can use somthing like string builder to rebuild how you would like.

    char delimiter = ' ';
    String[] temp = str.Split(delimiter);

    Now temp holds each word in the a diffrent array place;
    temp[0] = "Hello"
    temp[1] = "This"
    temp[2] = "Is"
    temp[3] = "My"
    temp[4] = "String"

    Im not to familar with string builder off hand right now but i know u can concatanate string and then u can just use a for loop running backwards to reverse the order.. I am sure there is an easier way though.

    for(int i = temp.Count - 1; i >= 0; i--
    {
    Or somthing along thoes lines

    }

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Vector to String and Reverse
    By Kyle Joseph Klouzal in forum C and C++
    Replies: 2
    Last Post: 07-10-2011, 09:11 PM
  2. TASM Simple Reverse String Algorithm
    By assembler_wanna_be in forum Assembly
    Replies: 3
    Last Post: 12-15-2010, 01:17 AM
  3. Replies: 17
    Last Post: 09-23-2010, 09:58 AM
  4. Stack allocation and stack size
    By mircan in forum C and C++
    Replies: 3
    Last Post: 03-17-2010, 06:53 PM
  5. Reverse a string
    By Termana in forum CSharp Tutorials
    Replies: 5
    Last Post: 11-30-2008, 01:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts