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