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 두가 미를 담 다.
  1. 방법
  2. 고민

두 링 모두 된다고 다. 근 배들게 물. 로 고민, 를 만들. 로그래밍다를 것 다.

그리고 방법나, 로 따라가 다. 그러나 단발 두드러기가 날 모르겠군. ^^;; 는 그 다. --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.0160 sec