2017-08-16 22 views
1

私はプログラミングに初心者であり、このC++スクールクイズを持っています。C++配列要素を右に押し出す

入力された配列要素を右側にプッシュしたかったのです。ここ

// automatac++.cpp : Defines the entry point for the console application. 
// 

#include "stdafx.h" 
#include <iostream> 
#include <list> 
#include <iterator> 
#include <conio.h> 
#include <cstring> 

//using namespace std; 
using std::cout; 
using std::cin; 
using std::endl; 
void menu_sel(); 
void push_element(); 
//void rem_element(); 

int in; 
char array[100]; 

int p_elements; 

int main() 
{ 

    menu_sel(); 

    return 0; 
} 

void push_element() { 
    int p_elements; 

    for (int e = 0; e < 10; e++) { 


    } 

    cout << "Enter number of elements:"; 
    cin >> p_elements; 
    cout << "Enter only " << p_elements << " elements"<<endl; 

    for (int e = 0; e < p_elements; e++ ) { 
     cin >> array[e]; 
    } 
    cout << "Pushed elements are :"; 
    for (int e = 0; e < p_elements; ++e) { 
     cout << array[e]<<" "; 

    } 

    //getch(); 
    menu_sel(); 

} 
/* 
void rem_element() { 
    char remove; 
    int arr_position; 

    cout << "You have selected Pop.\nRemove elements from arrays \n"; 
    cout << "Enter data to remove"; 
    cin >>remove; 

    for (int ie -) { 

    } 


    system("pause"); 



} 
*/ 


void menu_sel() { 


    int input; 
    cout << "\n****Menu Selection Here****"; 
    cout << "\n1. Push \n2. Pop \n3. Exit \n"; 
    cout << "select options here :"; 
    cin >> input; 

    switch (input) { 
    case 1: 
     cout << "You have selected Push Stack\n"; 
     push_element(); 
     break; 

    case 2: 
     //cout << "You have selected Pop Stack\n"; 
     //rem_element(); 
     break; 

    default: 
     cout << "You have selected Invalid Options";  
     break; 
     system("cls"); 
     return; 

    } 
} 

BLOCKQUOTE

私の既存のコード

であり、ここで出力した

the output shows pushing elements to the left

出力にある3 E R 4

は、私はあなたがそのように表示したい場合は、常に出力のために後方あなたの配列を読むことができる「4のR E 3」

おかげに関して、

答えて

0

のような出力を示したかったのです。

for (int e = p_elements-1; e >= 0; --e) { 
    cout << array[e]<<" "; 

} 
+0

ありがとうございます。 – RCX