메뉴 건너뛰기

2019_1 자료구조론(실습) (12297)



10주차 실습 code

setUID 2019.05.08 16:50 조회 수 : 1503

#include <stdio.h>

#include <stdlib.h>

 

//Node

typedef struct elementNode{

int data;

struct elementNode* nextNode;

}Node;

 

//Global list

//Node* list;

 

void Append(Node**, int);

void Show(Node*);

void Renew(Node*, int, int);

 

int main(int argc, char* argv[], char* env[])

{

Node* head = NULL;

 

Append(&head, 10);

Show(head);

 

return 0;

}

 

void Show(Node* head)

{

while(NULL != head){

printf("%d ", head->data);

head = head->nextNode;

}

}

 

void Append(Node** head, int data)

{

Node* newNode = (Node*)malloc(sizeof(Node));

newNode->data = data;

newNode->nextNode = NULL;

 

if(NULL == *head){

 

*head = newNode;

 

}else{

 

Node* tmpNode = *head;

 

while(NULL != tmpNode->nextNode && tmpNode->nextNode->data < newNode->data){

tmpNode = tmpNode->nextNode;

}

 

if(NULL == tmpNode->nextNode){

//여기는 끝에 들어가는 경우

tmpNode->nextNode = newNode;

}else{

//중간에 들어가는 경우

newNode->nextNode = tmpNode->nextNode;

tmpNode->nextNode = newNode;

}

}

}

 

void Renew(Node* head, int transaction, int renewTransaction)

{

Node* tempNode = head;

 

while(NULL != tempNode)

{

if(tempNode->data == transaction){

break;

}

 

tempNode = tempNode->nextNode;

}

 

if(NULL != tempNode){

 

printf("find it!!!!!!! \n");

printf("renew transaction value : ");

 

tempNode->data = renewTransaction;

}

}

위로