공부하는중. 틀린점이 많으니 따라하지말길
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
struct msList{
char* data;
struct msList* nList; //다음 노드의 주소값을 갖는다
};
struct msListHead{
int eNo;
msList* nList; //첫 노드의 주소값을 갖는다
};
void addList(){
}
int main(void){
struct msListHead mListHead; //header 생성
//init
mListHead.eNo=0;
mListHead.nList=NULL; //head=>null
//add data at emptyNode
struct msList mList; //node생성
char* name={"kimmansung"}; //데이터추가
mList.data=(char*)calloc(strlen(name)+1,sizeof(char)); //need free
strcpy(mList.data,name); //copy 2 node
mList.nList=NULL; // node=>null
//add Node at Head
mListHead.nList=&mList; //head=>node=>null
mListHead.eNo++; //cnt ++
cout<<mListHead.nList->data<<endl;
//delete Node at Head
msList* tempPtr=mListHead.nList;
mListHead.nList=NULL;
free(tempPtr->data);
mListHead.eNo--;
cout<<mListHead.eNo<<endl;
return 0;
}
'소프트웨어 > C/C++' 카테고리의 다른 글
자료구조] 재귀를 이용한 이진트리 순환탐색 (0) | 2013.08.19 |
---|---|
c/c++] malloc에서 HEAP CORRUPTION DETECTED 오류가 날땐.. (0) | 2013.08.18 |
c++] 리스트 함수별로 나눈 (0) | 2013.08.16 |
c/c++] 동적할당실패시 try catch (0) | 2013.08.11 |
c/c++] try catch (0) | 2013.08.11 |
c/c++] 템플릿 (0) | 2013.08.11 |
c/c++] 연산자오버로딩(=이용)할때 주의(얕은복사,깊은복사) (0) | 2013.08.11 |