Televison & Video Logo

Related Topics:

B
Bhumitmi Posted on Nov 01, 2013
Answered by a Fixya Expert

Trustworthy Expert Solutions

At Fixya.com, our trusted experts are meticulously vetted and possess extensive experience in their respective fields. Backed by a community of knowledgeable professionals, our platform ensures that the solutions provided are thoroughly researched and validated.

View Our Top Experts

Write a program that creates a linked list of characters from a string entered by the user. (The string can be initially entered into an array if you wish.) Your program is then to move the second part of the string (based on an index) to the front of the first part of the string. This is to be achieved by the user entering an integer which will be the index (counting from 0).

1 Answer

kakima

Level 3:

An expert who has achieved level 3 by getting 1000 points

One Above All:

The expert with highest point at the last day of the past 12 weeks.

Top Expert:

An expert who has finished #1 on the weekly Top 10 Fixya Experts Leaderboard.

Superstar:

An expert that got 20 achievements.

  • Televison & ... Master 102,366 Answers
  • Posted on Nov 01, 2013
kakima
Televison & ... Master
Level 3:

An expert who has achieved level 3 by getting 1000 points

One Above All:

The expert with highest point at the last day of the past 12 weeks.

Top Expert:

An expert who has finished #1 on the weekly Top 10 Fixya Experts Leaderboard.

Superstar:

An expert that got 20 achievements.

Joined: Dec 16, 2009
Answers
102366
Questions
0
Helped
10432887
Points
622693

Here's a brute-force C++ program to do it, assuming FixYa doesn't mangle the formatting. The last loop merely outputs the resulting list, since it makes no sense to just do all the work without showing the result.

====================
#include <iomanip>
#include <iostream>
#include <list>
#include <string>
using namespace std;
int main()
{
int brk, j;
list<char> lst;
string str;
cin >> str;
for (string::const_iterator i(str.begin()); i != str.end(); ++i)
lst.push_back(*i);
cin >> brk;
j = 0;
for (list<char>::iterator i(lst.begin()); j < brk; ++j) {
lst.push_back(*i);
lst.erase(lst.begin(), ++i);
}
for (list<char>::const_iterator i(lst.begin()); i != lst.end(); ++i)
cout << *i;
cout << endl;
return 0;
}
====================

  • kakima Nov 01, 2013

    Yep, FixYa mangled the formatting. I'll leave it to you to re-indent the code.

×

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

0helpful
1answer

How to write a program to translate english text to binary string and write a program to do inverse 27 = . , 28 = , 29= ? 30 = . 31=

to convert from text to binary, you would do something along the following lines..
1. have the user enter a string.
2. loop through the string (for each char in stringEntered..)
3. convert the character to binary using the methods provided to you by your language of choice

For the reverse (binary to text):
you must take 8 bits of data (which would be a single character), and convert it to text using the methods provided by your language of choice..

here's some links that might be of interest to you.
Visual FoxPro VFP CTOBIN and BINTOC Functions Equivalent In Net The Most Accurate and Reliable Source Code Converters
0helpful
1answer

Write a pseudocode declaration for a string array initialized with the following strings einstein newton

the nice thing about pseudocode is that there's many ways to do it
E.g 1;
String str = new Array["einstein',"newton"];
E.g 2;
myStringArray = new Array{'einstein','newton'}

BOTH of the above are correct, because they are pseudocode
0helpful
1answer

How do I divide the word meat into syllables?

Given your list of words, It appears to me that what makes up a syllable is the vowels in the word.. each time 1 or more vowels are separated by 1 or more consonants/symbols, a syllable is born.
so, have an array of characters containing vowels.
now iterate through the given word and create a new syllable(String) by adding the characters you are inspecting until you find a vowel.. now continue to add the vowels you find until you find a consonant/symbol.. that's where your new syllable ends (you can add it to a List if you want or just output it to the command line) ..and if you haven't gone through the entire word yet, create a new syllable(String) and repeat the process.

Good luck
0helpful
1answer

Divide the word Dangerous into syllabes

(sounds like a school assignment to me) ;-)

-count (& save) the 3 characters (1st syllable).
-start at position 4 (3+1 chars) in the string.
-count (& save) the 3 characters (2nd syllable).
-start at position 7 (6+1 chars) in the string.
-count (& save) the 3 characters (3rd syllable).

Logic:

-Initialize syllable-counter (x) to 1, position-counter to 1 (z).
-Initialize syl(x) strings to Null, where x = 1 to 3.
-Assign "dangerous" to string variable.

z = 1
y = 1
x = 1
string = "DANGEROUS"

For x = 1 to 3 DO
*Comment. read 3 chars (in a loop), add them to Syl (x).
For y = 1 to 3 DO
read a char(y) from the string at position-counter(z)
syl(x) = syl(x) + char(y)
z = z + 1
END DO
END DO


NOTE: not 100%, but close.
2helpful
1answer

Define a character array and use strcpy() to copy a string into it. Print the string out by using a loop with a pointer to print out one character at a time. Initialize the pointer to the first element and...

Nice, computer science homework.
int main () { char str[]="this is my string";
//print our string forwards int i = 0; while(str[i]!="\0") { putchar( str[i] ); i++; }
//newline putchar('\n');
//print our string backwards int length = strlen(str); while(length--) { putchar( str[length] ); } }
I didn't test this to make sure it worked, but this is the general way of doing this. It looks like your professor wants you to use pointers. I used pointers here. Do you know how? Arrays are pointers with some syntactic sugar.
I wouldn't rely on sites like this to get answers to your homework. Even if you get the right answer, there's always the possibility of your CS professor finding this answer online and then making your future homework ten times harder.
5helpful
2answers

Setting secured wireless connection

You can enable WEP on your router.

In the address bar of your browser, type 192.168.0.1 to access the setup page of the Dlink router.

By default the username is admin and leave the password blank.

On the Setup page, go to Wireless.

Security Mode should be WEP then click Next.

You can change the WEP KEY 1. Make sure you remember this because you will need to enter this on your wireless computer.

Save the settings.

I hope this helps!
0helpful
1answer

How to convert infix to postfix using stacks in java programming?

u can try the follwing coding
import java.io.*;
import java.util.*;
//begin coding for the stack interface
interface Stack<E>
{
public boolean isEmpty();//tests is current stack is empty. Returns true if so, and false if not.
public E top() throws StackException;//retrieves value at the top of the stack. Stack cannot be empty.
public void push(E value) throws StackException;//pushes a value on the top of the stack.
public void pop() throws StackException;//removes a value from the top of the stack. Stack cannot be empty.
}//terminates coding of Stack interface

//begin coding for the objArrayStack class
class objArrayStack<E> implements Stack<E>
{
//constructor
public objArrayStack()
{
topValue=-1;
}//terminates constructor
public void push(E value)throws StackException
{
if(topValue<ArraySize-1)//currrent stack is not full
{
++topValue;
Info[topValue]=value;
}//terminates if
else //current stack is full
throw new StackException("Error: Overflow");
}//terminates push method
public void pop() throws StackException
{
if(!isEmpty())//current stack is not empty
--topValue;
else //stack is empty
throw new StackException("Error: Underflow");
}//terminates pop method
public boolean isEmpty()
{
return topValue==-1;
}//terminates isEmpty method
public E top() throws StackException
{
if(!isEmpty())//stack is not empty
return (E)Info[topValue];
else //stack is empty
throw new StackException("Error: Underflow");
}//terminates top method
//declare instance variables
final int ArraySize=10;
private Object Info[]=new Object[ArraySize];
private int topValue;

//begins coding for the StackException class
class StackException extends RuntimeException
{
//constructor
public StackException(String str)
{
super(str);
}//terminates text of constructor
}//terminates text of StackException class

//method to convert from infix to postfix notation
public static String InToPost(String infixString)
{
//operator stack initialized
objArrayStack<Character> operatorStack = new objArrayStack<Character>();
//postfix string initialized as empty
String postfixString = " ";
//scan infix string and take appropriate action
for(int index = 0; index < infixString.length(); ++index)
{
char chValue = infixString.charAt(index);
if(chValue == '(')
operatorStack.push('(');
else if(chValue == ')')
{
Character oper = operatorStack.top();
while(!(oper.equals('(')) && !(operatorStack.isEmpty()))
{
postfixString += oper.charValue();
operatorStack.pop();
oper = operatorStack.top();
}//end while loop
operatorStack.pop();
}//end else if
else if(chValue == '+' || chValue == '-')
{
if(operatorStack.isEmpty()) //operatorStack is empty
operatorStack.push(chValue);
else //current operatorStack is not empty
{
Character oper = operatorStack.top();
while(!(operatorStack.isEmpty() || oper.equals(new Character('(')) || oper.equals(new Character(')'))))
{
operatorStack.pop();
postfixString += oper.charValue();
}//ends while loop
operatorStack.push(chValue);
}//end else
}//end else if
else if(chValue == '*' || chValue == '/')
{
if(operatorStack.isEmpty())
operatorStack.push(chValue);
else
{
Character oper = operatorStack.top();
while(!oper.equals(new Character('+')) && !oper.equals(new Character('-')) && !operatorStack.isEmpty())
{
operatorStack.pop();
postfixString += oper.charValue();
}//end while loop
operatorStack.push(chValue);
}//end else
}//end else if
else
postfixString += chValue;
}//end for loop
while(!operatorStack.isEmpty())
{
Character oper = operatorStack.top();
if(!oper.equals(new Character('(')))
{
operatorStack.pop();
postfixString += oper.charValue();
}//end if
}//end while
return postfixString ;
}//terminates text of InToPost method

public static void main(String[]args)
{
objArrayStack mystack = new objArrayStack();
System.out.println("Enter a string");
Scanner scan = new Scanner(System.in);
scan.nextLine();
String str = scan.nextLine();
InToPost(str);
}//terminates text of main method
}//terminates text of objArrayStack class
0helpful
1answer

Programming

This sounds remarkably like a homework assignment type of question. Any C++ reference book will contain examples of this. Also, look for books about data structures which will contain not only examples of the above, but complete explanations of the concepts and uses of each.
Dan
Not finding what you are looking for?

77 views

Ask a Question

Usually answered in minutes!

Top Televison & Video Experts

Grand Canyon Tech
Grand Canyon Tech

Level 3 Expert

3867 Answers

Cindy Wells

Level 3 Expert

6688 Answers

 Grubhead
Grubhead

Level 3 Expert

5755 Answers

Are you a Televison and Video Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...