<div>연결리스트 스텍을 만들고 있는데</div> <div>리스트 안에 문자열을 저장해주고 싶어서 질문드립니다!</div> <div>저장할 문자열은 한글입니다.</div> <div> </div> <div>연결 리스트 스텍안에 배열형식으로 item을 받을 수 있을까요?</div> <div>예를 들어서 홍길동 이면 item[6]가 되게 malloc해준다음 받아주고 다음 리스트로 넘기기</div> <div>이렇게 해주고 싶어서요... </div> <div> </div> <div> </div> <div>제가 쓰고있는 스텍 소스입니다.</div> <div> </div><pre style="margin:0px;line-height:125%;">typedef char element; typedef struct StackNode { element item; struct StackNode <span style="color:rgb(51,51,51);">*</span>link; }StackNode; typedef struct { StackNode <span style="color:rgb(51,51,51);">*</span>top; }LinkedStackType; <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">초기화</span>void init(LinkedStackType <span style="color:rgb(51,51,51);">*</span>s) { s<span style="color:rgb(51,51,51);">-></span>top <span style="color:rgb(51,51,51);">=</span> NULL; } <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">비어있음</span><span style="color:rgb(0,112,32);">int</span> is_empty(LinkedStackType <span style="color:rgb(51,51,51);">*</span>s) { <span style="color:rgb(0,136,0);font-weight:bold;">if</span> (s<span style="color:rgb(51,51,51);">-></span>top <span style="color:rgb(51,51,51);">==</span> NULL) <span style="color:rgb(0,136,0);font-weight:bold;">return</span> TRUE; <span style="color:rgb(0,136,0);font-weight:bold;">else</span> <span style="color:rgb(0,136,0);font-weight:bold;">return</span> FALSE; } <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">삽입</span>void push(LinkedStackType <span style="color:rgb(51,51,51);">*</span>s, element item) { StackNode <span style="color:rgb(51,51,51);">*</span>temp <span style="color:rgb(51,51,51);">=</span> (StackNode <span style="color:rgb(51,51,51);">*</span>)malloc(sizeof(StackNode)); <span style="color:rgb(0,136,0);font-weight:bold;">if</span> (temp <span style="color:rgb(51,51,51);">==</span> NULL){ fprintf(stderr, <span style="background-color:rgb(255,240,240);">"메모리 할당에러</span><span style="color:rgb(102,102,102);font-weight:bold;background-color:rgb(255,240,240);">\n</span><span style="background-color:rgb(255,240,240);">"</span>); <span style="color:rgb(0,136,0);font-weight:bold;">return</span>; } <span style="color:rgb(0,136,0);font-weight:bold;">else</span>{ temp<span style="color:rgb(51,51,51);">-></span>item <span style="color:rgb(51,51,51);">=</span> item; temp<span style="color:rgb(51,51,51);">-></span>link <span style="color:rgb(51,51,51);">=</span> s<span style="color:rgb(51,51,51);">-></span>top; s<span style="color:rgb(51,51,51);">-></span>top <span style="color:rgb(51,51,51);">=</span> temp; } } <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">삭제</span>element pop(LinkedStackType <span style="color:rgb(51,51,51);">*</span>s) { <span style="color:rgb(0,136,0);font-weight:bold;">if</span> (is_empty(s)){ fprintf(stderr, <span style="background-color:rgb(255,240,240);">"스택이 비어있음.</span><span style="color:rgb(102,102,102);font-weight:bold;background-color:rgb(255,240,240);">\n</span><span style="background-color:rgb(255,240,240);">"</span>); <span style="color:rgb(0,112,32);">exit</span>(<span style="color:rgb(0,0,221);font-weight:bold;">1</span>); } <span style="color:rgb(0,136,0);font-weight:bold;">else</span>{ StackNode <span style="color:rgb(51,51,51);">*</span>temp <span style="color:rgb(51,51,51);">=</span> s<span style="color:rgb(51,51,51);">-></span>top; <span style="color:rgb(0,112,32);">int</span> item <span style="color:rgb(51,51,51);">=</span> temp<span style="color:rgb(51,51,51);">-></span>item; s<span style="color:rgb(51,51,51);">-></span>top <span style="color:rgb(51,51,51);">=</span> s<span style="color:rgb(51,51,51);">-></span>top<span style="color:rgb(51,51,51);">-></span>link; free(temp); <span style="color:rgb(0,136,0);font-weight:bold;">return</span> item; } } <span style="color:rgb(51,51,51);">//</span><span style="color:rgb(255,0,0);background-color:rgb(255,170,170);">피크</span>element peek(LinkedStackType <span style="color:rgb(51,51,51);">*</span>s) { <span style="color:rgb(0,136,0);font-weight:bold;">if</span> (is_empty(s)){ fprintf(stderr, <span style="background-color:rgb(255,240,240);">"스택이 비어있음.</span><span style="color:rgb(102,102,102);font-weight:bold;background-color:rgb(255,240,240);">\n</span><span style="background-color:rgb(255,240,240);">"</span>); <span style="color:rgb(0,112,32);">exit</span>(<span style="color:rgb(0,0,221);font-weight:bold;">1</span>); } <span style="color:rgb(0,136,0);font-weight:bold;">else</span>{ StackNode <span style="color:rgb(51,51,51);">*</span>temp <span style="color:rgb(51,51,51);">=</span> s<span style="color:rgb(51,51,51);">-></span>top; <span style="color:rgb(0,112,32);">int</span> item <span style="color:rgb(51,51,51);">=</span> temp<span style="color:rgb(51,51,51);">-></span>item; s<span style="color:rgb(51,51,51);">-></span>top <span style="color:rgb(51,51,51);">=</span> s<span style="color:rgb(51,51,51);">-></span>top<span style="color:rgb(51,51,51);">-></span>link; <span style="color:rgb(0,136,0);font-weight:bold;">return</span> item; } } </pre>
<a href="http://steamcommunity.com/id/zpq456/">http://steamcommunity.com/id/zpq456/</a>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.