-
Notifications
You must be signed in to change notification settings - Fork 0
가천대학교 윤성우 링크드리스트 #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Qstion05
wants to merge
3
commits into
master
Choose a base branch
from
gachon_yun
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
가천대학교 윤성우 링크드리스트 #52
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #include<iostream> | ||
| #include<malloc.h> | ||
| using namespace std; | ||
|
|
||
| struct List_node | ||
| { | ||
|
|
||
| int DATA = 0; | ||
| struct List_node *NEXT_NODE; | ||
| List_node(int D):DATA(D){NEXT_NODE = NULL;} | ||
| }; | ||
|
|
||
| int main(){ | ||
| List_node *HEAD = NULL; | ||
| List_node *TAIL = NULL; | ||
| List_node *CURSOR = NULL; | ||
| List_node *NEW_NODE = NULL; | ||
| int input_data; | ||
|
|
||
| for(int i = 0; i < 5; i++){ | ||
| cout << "자연수를 입력해주세요 : "; | ||
| cin >> input_data; | ||
| NEW_NODE = new List_node(input_data); //새로운 노드를 선언하고. | ||
| if(HEAD == NULL) //만약, HEAD가 가리키는 노드가 없으면, | ||
| HEAD = NEW_NODE; //HEAD는 추가된 노드를 가르킨다. | ||
| else//HEAD가 가리키는 노드가 있으면, | ||
| TAIL -> NEXT_NODE = NEW_NODE; //TAIL이 가리키는 노드(=직전에 추가된 노드)의 NEXT변수가 새로 추가되는 노드를 가리키게 만들고. | ||
Joe2357 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| TAIL = NEW_NODE; //TAIL은 새로 추가한 노드를 가리킨다. | ||
| } | ||
|
|
||
| cout<<""<<endl; | ||
| CURSOR = HEAD; //CURSOR는 첫번째 노드를 가리킨다. | ||
| cout<<"1번째 노드에 저장된 데이터: "<<CURSOR->DATA<<endl; //CURSOR이 가리키는 노드에 저장된 데이터값을 출력한다. | ||
| for(int j = 0; j < 4; j++){ | ||
| CURSOR = CURSOR -> NEXT_NODE; //CURSOR이 현재 가리키는 노드의 다음 노드를 가리킨다. | ||
| cout<<j+2<<"번째 노드에 저장된 데이터: "<<CURSOR->DATA<<""<<endl; //CURSOR이 가리키는 노드에 저장된 데이터값을 출력한다. | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 할당해제 하세요. |
||
|
|
||
| //할당 해제 | ||
| if (HEAD == NULL) | ||
| return 0; | ||
| else{ | ||
| List_node *delNode = HEAD; //delNode를 만들고, HEAD를 가르킴. | ||
| List_node *delNextNode = HEAD -> NEXT_NODE;//delNextNode를 만들고, HEAD의 NEXT 변수를 저장함. | ||
| delete(delNode); //delNode에 배정된 Heap 메모리를 할당 해제 함. | ||
| for(int k = 0; k < 4; k++) | ||
| { | ||
| delNode = delNextNode; //delNode는 delNextNode가 가르키는 NEXT 변수가 가르키는 노드를 가르킴. | ||
| delNextNode = delNextNode->NEXT_NODE; //delNextNode는 현재 노드의 NEXT변수를 저장함. | ||
| delete(delNode); ////delNode에 배정된 Heap 메모리를 할당 해제 함. | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #include<iostream> | ||
| #include<malloc.h> | ||
| using namespace std; | ||
|
|
||
| struct List_node | ||
| { | ||
|
|
||
| int DATA = 0; | ||
| struct List_node *NEXT_NODE; | ||
| List_node(int D):DATA(D){NEXT_NODE = NULL;} | ||
| }; | ||
|
|
||
| int main(){ | ||
| List_node *HEAD = NULL; | ||
| List_node *TAIL = NULL; | ||
| List_node *CURSOR = NULL; | ||
| List_node *NEW_NODE = NULL; | ||
| int input_data; | ||
|
|
||
| for(int i = 0; i < 5; i++){ | ||
| cout << "자연수를 입력해주세요 : "; | ||
| cin >> input_data; | ||
| NEW_NODE = new List_node(input_data); //새로운 노드를 선언하고. | ||
| if(HEAD == NULL) //만약, HEAD가 가리키는 노드가 없으면, | ||
| HEAD = NEW_NODE; //HEAD는 추가된 노드를 가르킨다. | ||
| else//HEAD가 가리키는 노드가 있으면, | ||
| TAIL -> NEXT_NODE = NEW_NODE; //TAIL이 가리키는 노드(=직전에 추가된 노드)의 NEXT변수가 새로 추가되는 노드를 가리키게 만들고. | ||
| TAIL = NEW_NODE; //TAIL은 새로 추가한 노드를 가리킨다. | ||
| } | ||
|
|
||
| cout<<""<<endl; | ||
| CURSOR = HEAD; //CURSOR는 첫번째 노드를 가리킨다. | ||
| cout<<"1번째 노드에 저장된 데이터: "<<CURSOR->DATA<<endl; //CURSOR이 가리키는 노드에 저장된 데이터값을 출력한다. | ||
| for(int j = 0; j < 4; j++){ | ||
| CURSOR = CURSOR -> NEXT_NODE; //CURSOR이 현재 가리키는 노드의 다음 노드를 가리킨다. | ||
| cout<<j+2<<"번째 노드에 저장된 데이터: "<<CURSOR->DATA<<""<<endl; //CURSOR이 가리키는 노드에 저장된 데이터값을 출력한다. | ||
| } | ||
|
|
||
| //할당 해제 | ||
| if (HEAD == NULL) | ||
| return 0; | ||
| else{ | ||
| List_node *delNode = HEAD; //delNode를 만들고, HEAD를 가르킴. | ||
| List_node *delNextNode = HEAD -> NEXT_NODE;//delNextNode를 만들고, HEAD의 NEXT 변수를 저장함. | ||
| delete(delNode); //delNode에 배정된 Heap 메모리를 할당 해제 함. | ||
| for(int k = 0; k < 4; k++) | ||
| { | ||
| delNode = delNextNode; //delNode는 delNextNode가 가르키는 NEXT 변수가 가르키는 노드를 가르킴. | ||
| delNextNode = delNextNode->NEXT_NODE; //delNextNode는 현재 노드의 NEXT변수를 저장함. | ||
| delete(delNode); ////delNode에 배정된 Heap 메모리를 할당 해제 함. | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
생성자, 메서드 쓰세요.