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.0193 sec