Array element shifting to the Left and the Right

One time set up a program, a programmer may also need to knowabout the array. Basically an array of some data blocks are put together in a variable. It will be easier for us to calculate the number of characters or move the data to the index to the left or right. As an example, we have input a sentence such as PISANG JAMBU,then if the array element in the shift to the left of the expected resultsare Anana ISANG JAMBUP and if the return on the slide to the right,then the expected return to the original, the PISANG JAMBU.Well, want to know what programming algorithm? Please note theflowchart and examples of using C + + program.



#include <iostream>

#include <string>

#include <iomanip.h>
using namespace std;
class Geser{
   friend istream& operator>>(istream&, Geser&);
   friend ostream& operator<<(ostream&, Geser&);
          void geser_kiri(const Geser&);
          void geser_kanan(const Geser&);
          void hitung();
           int i;
           char data[100];
           int banyak;
           int temp;
void Geser::geser_kiri(const Geser& A){
   banyak = A.banyak;
   temp   =[0];
   for(int i=0; i<=banyak-1; i++){
      if(i<banyak-1) data[i] =[i+1];
      else data[i] = temp;
void Geser::geser_kanan(const Geser& A){
   banyak = A.banyak;
   temp   =[banyak-1];
   for(int i=banyak; i>=0; i--){
      if(i>0) data[i] =[i-1];
      else    data[0] = temp;
void Geser::hitung(){
   banyak    = strlen(data);
istream& operator>>(istream& in, Geser& masukkan){
   cout << "Masukkan data kata : ";
   cin.getline(, 100);
   return in;
ostream& operator<<(ostream& out, Geser& keluar){
   for(int i=0; i<keluar.banyak; i++){
      cout <<[i] << " | ";
   cout << endl;
int main()
   Geser x;
   cin >> x;
   cout << endl << "#Data Array#" << endl;
   cout << x;
   cout << endl << "#Data Array Geser Ke Kiri#" << endl;
   cout << x;
   cout << endl << "#Data Array Geser Ke Kanan#" << endl;
   cout << x;
   cout << endl << "#Data Array Geser Ke Kanan (Lagi: 1 elemen)#" << endl;
   cout << x;
   cout << endl << "#Data Array Geser Ke Kanan (Lagi: 2 elemen)#" << endl;
   cout << x;
   cout << endl << endl;
   return 0;


Thank you.🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: