U E D R , A S I H C RSS

큐와 스택/문원명

...

string헤 include하 char *형 #1,#2,#3 strcpy 행한 ,
"empty" 화 하 PUSH, ... ..

AnswerMe .#1, #2, #3 . .

~cpp 
 #1 : strcpy(array[i], "empty");
 #2 : strcpy(array[0], "empty"); 
 #3 : strcpy(array[tail], "empty");
, . , . --NeoCoin

. --
(10 ) . 한 학 . . , . . , 학 , call By Value, call By reference Pointer . --NeoCoin

. --;;
~cpp 
#include <iostream>  
#include <string>

using namespace std;  
const int ASIZE = 5;  


// VC++ 7.0  , 행하     .
// VC++ 6.0 ,  release    . 
void main()  
{  
    std::string a;
    char * array[ASIZE];    // Pointer . ,   .
                            // char       32bit  Pointer 5
                            // .
                            //  Pointer     .( )
    int tail = 0, status = 3;  
    int select, count;  
    for(int i = 0 ; i < ASIZE ; i++)  
        strcpy(array[i], "empty");    // Pointer     
                                    //  . VC++ 6.0 Debug    
                                    //         
                                    //  .  debug   한
                                    //    . Release   .
    do  
    {  
        cout << "1. PUSH   2. Pop   3. Stack   4. Queue   5. Show   6. Exit" << endl;  
        cin >> select;
        switch(select)  
        {  
        case 1 :   
            cout << " : ";  
            if (tail == ASIZE)   
            {  
                cout << " ." << endl;   
                break;  
            }  
            cin >> array[tail];  // array[tail]      
                                 // 하 Pointer.      
                                 //   .   ,   
                                 //  .                         
                                 
                                 
            tail++;  
            break;  
        case 2 :  
            if(status == 4)                 //큐  
            {  
                strcpy(array[0], "empty");   
                tail--;  
                for(count = 0 ; count < tail ; count++)  
                    array[count] = array[count+1];  // string  , Pointer  .
                                                    // string , call by value  class 
                                                    //    .      
                                                    //  .   char 포     .
                                                    //     .
            }  
            else                            //택  
            {  
                tail--;  
                strcpy(array[tail], "empty");  //  ,     .

            }  
            break;  
        case 3 :   
            status = 3;  
            break;  
        case 4 :  
            status = 4;  
            break;  
        case 5 :   

            for(count = 0 ; count < tail ; count++)  
            {  
                cout << array[count] << "]    ";  // ,    Pointer  
                                                // . , empty+null     
                                                //  ,    .
            }  
            cout << endl;  
            break;  
        case 6 :   
            break;  
        default :  
            cout << " 1 6   " << endl;  

        }  

    }while(select != 6);  
}  

, cin 통한 ~cpp std:string , char*

cin string ~cpp C:\Program Files\Microsoft Visual Studio\VC98\Include\istream . , Debug .
한 string .
~cpp 
string element;
cin >> element 
>> , string , 행합. .
~cpp 
    ...  ...
if (_Ok)    //  ?  enter, space  
        {    // state okay, extract characters
     ......
        _Str.erase();   // 할 string   element

        _TRY_IO_BEGIN   //   

        ///    ,   
        _Mysizt _Size = 0 < _Istr.width()   
            && (_Mysizt)_Istr.width() < _Str.max_size()
                ? (_Mysizt)_Istr.width() : _Str.max_size();                 
               
        ......

        /// 회하,  string  
        for (; 0 < _Size; --_Size, _Meta = _Istr.rdbuf()->snextc())
          ......
                _Str.append(1, _Traits::to_char_type(_Meta));   //  . , string  
                                                                //  .
         ......
,
~cpp 
char* element;
cin >> element;
팅하 . .
~cpp 
......
*_Str++ = _Traits::to_char_type(_Meta);	// _Str   char* 형 element . ,     .
                                              // , element      .
                                              //   OS      , 
                                              //  .
......


.. ?
DeleteMe .



. . , . .

, . . ^^;; . --NeoCoin
ps. ZeroWiki . 하, .



~cpp 
#include <iostream>
#include <string>
using namespace std;
const int ASIZE = 5;

void main()
{
	string array[ASIZE];
	int tail = 0, status = 3;
	int select, count;
	for(int i = 0 ; i < ASIZE ; i++)
		array[i] = "empty";					//#1
	do
	{
		cout << "1. PUSH   2. Pop   3. Stack   4. Queue   5. Show   6. Exit" << endl;
		cin >> select;
		switch(select)
		{
			case 1 : 
				cout << " : ";
				if (tail == ASIZE) 
				{
					cout << " ." << endl; 
					break;
				}
				cin >> array[tail];
				tail++;
				break;
			case 2 :
				if(status == 4)			//큐
				{
					array[0] = "empty";		//#2
					tail--;
					for(count = 0 ; count < tail ; count++)
						array[count] = array[count+1];
				}
				else				//택
				{
					tail--;
					array[tail] = "empty";		//#3
				}
				break;
			case 3 : 
				status = 3;
				break;
			case 4 :
				status = 4;
				break;
			case 5 : 
				
				for(count = 0 ; count < tail ; count++)
				{
					cout << array[count] << "]\t";
				}
				cout << endl;
				break;
			case 6 : 
				break;
			default :
				cout << " 1 6   " << endl;
		
		}

	}while(select != 6);
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:31:19
Processing time 0.0337 sec