Thread: What kind of data structure I should to use?

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    9

    What kind of data structure I should to use?

    Hey, I wonder which data structure I should use to have faster transferring of letters in string.
    For example : I've got two words „GHIJ” and „IGHJ” and my job is changing adjacent letters in first word to make a second word.
    So next steps of my program are:
    1. start : GHIJ
    2. 1st operation : GIHJ
    3. 2nd operation : IGHJ
    But number of operations can reduce to:
    1. start: GHIJ
    2. 1st operation: IGHJ
    So at the beginning of word I moved 'I', automatically 2 letters after 'I' I moved one position forward.
    Does the best solution of problem like this is two-way list or is there any other way to make it faster?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Since you are only swapping elements, I'd say you don't need anything besides a vector.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Yeah, just stick to strings. Words are too short for anything more complicated to bring any benefit.

    It's always possible to reorder any string using adjacent swaps, but I don't understand why you would want to. Are you trying to generate anagrams?
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. difference between data object and data structure?
    By c_lady in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2011, 12:30 PM
  2. Data structure for storing serial port data in firmware
    By james457 in forum C Programming
    Replies: 4
    Last Post: 06-15-2009, 09:28 AM
  3. data structure design for data aggregation
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-20-2008, 06:43 AM
  4. Return some kind of array or structure?
    By DARKGuy in forum C++ Programming
    Replies: 6
    Last Post: 04-23-2007, 07:29 PM
  5. Data Structure
    By sunnypalsingh in forum C++ Programming
    Replies: 2
    Last Post: 10-09-2005, 08:27 PM