*성*
개인인증
판매자 정보
- 학교정보
-
입력된 정보가 없습니다.
- 직장정보
-
입력된 정보가 없습니다.
- 자격증
-
판매지수
-
- 판매중 자료수
- 13개
-
- 전체 판매량
- 72개
-
- 최근 3개월 판매량
- 0개
-
- 자료후기 점수
- 평균A
-
- 자료문의 응답률
- -
전체자료 13개
-
-
[자료구조 프로그램 소스] 연결리스트 스택과 특정노드삽입삭제소스
평가A좋아요
-
◎ 연습문제 1) 스택을 연결리스트(linked list)로 구현했을 때, 삽입과 삭제 연산 후의 연결 리스트를 출력하라.#include #include typedef struct stacklist{int data;struct stacklist *next;}*Node;void linkedpush(Node *top);void linkedpop(Node *top);void printnode(Node *top);void main(){int number;Node top=0;printf("스택을 연결리스트로 구현한 프로그램입니다.n");do {printf("1.삽입 2.삭제 3.출력 4.종료 ");scanf("%d",&number);switch(number) {case 1:linkedpush(&top);printnode(&top);break;case 2:linkedpop(&top);printnode(&top);break;case 3:printnode(&top);break;default:break;}}while(number!=4);}void linkedpush(Node *top){int x;printf("데이터를 입력하세요. ");scanf("%d",&x);Node temp=(Node)malloc(sizeof(stacklist));temp->data = x;temp->next = *top;*top = temp;}void linkedpop(Node *top){Node temp=*top;if(temp != NULL) {temp = temp->next;*top = temp; }}void printnode(Node *top){Node temp=*top;printf("n=스택결과값=n");if(temp != NULL)while(temp) {printf(" %dn",temp->data);temp = temp->next;}elseprintf("자료없당");printf("n");}{{◎ 연습문제 2) linked list를 구현(연결리스트에 있는 특정 노드 값을 찾아서 삭제 또는 특정 노드 다 음에 삽입하는 연산을 수행한 결과 리스트 출력)하라.#include #include typedef struct stacklist{int data;struct stacklist *next;}*Node;void linkedpush(Node *top); //삽입함수void linkedpop(Node *top); //삭제함수void printnode(Node *top); //출력함수void searchpush(Node *top); //특정삽입함수void searchpop(Node *top); //특정노드삭제함수void main(){int number;Node top=0;printf("연결리스트로 특정노드삽입삭제를 구현한 프로그램입니다.n");do {printf("1.삽입 2.삭제 3.출력 4.특정삽입 5.특정삭제 6.종료 ");scanf("%d",&number);switch(number) {case 1:linkedpush(&top);printnode(&top);break;case 2:linkedpop(&top);printnode(&top);break;case 3:printnode(&top);break;case 4:searchpush(&top);printnode(&top);break;case 5:searchpop(&top);printnode(&top);default:break;}}while(number!=6);}void linkedpush(Node *top){int x;printf("데이터를 입력하세요. ");scanf("%d",&x);Node temp=(Node)malloc(sizeof(stacklist));temp->data = x;temp->next = *top;*top = temp;}void searchpush(Node *top){int search,x;printf("찾을 데이터는요? ");scanf("%d",&search);printf("찾은 데이터 바로 뒤에 입력하도록 하겠습니다.n");printf("입력 데이터는요? ");scanf("%d",&x);Node snode=*top;if(snode == NULL) //초기 상태{snode = (Node)malloc(sizeof(stacklist));snode->data = x;snode->next = NULL;*top = snode;return;}while(search != snode->data && snode->next != NULL) //특정노드 삽입검색수행snode = snode->next;if(search!=snode->data && snode->next == NULL)printf("n찾을 데이터가 없어서 삽입하지 못했습니다.n");else {Node temp=(Node)malloc(sizeof(stacklist)); //노드 삽입 후 포인터변환temp->data = x;temp->next = snode->next;snode->next = temp; }}void searchpop(Node *top){int search;printf("찾을 데이터는요? ");scanf("%d",&search);printf("찾은 데이터 바로 삭제토록 하겠습니다.n");Node i=*top,j;j = NULL;if (i == NULL)return;while(search != i->data && i->next != NULL) { //특정노드 삭제검색수행j = i;i = i->next; }if(search!=i->data && i->next == NULL)printf("n찾을 데이터가 없어서 삭제하지 못했습니다.n");else {if(i->next == NULL && j != NULL) { //가장 마지막 노드 삭제j->next = NULL;free(i); }else if(i == *top) { //가장 처음 노드 삭제*top = i->next;free(i); }else {j->next = i->next; //중간 노드 삭제free(i); }}}void linkedpop(Node *top){Node temp=*top;if(temp != NULL) //temp가 널인지를 체크{temp = temp->next;*top = temp;}}void printnode(Node *top){Node temp=*top;if (!temp) //공백인 경우 메시지 출력{printf("empty listn");return;}printf("n");while(temp) {printf("%d ",temp->data);temp = temp->next;}printf("nn");}{{{
-
프로그램소스|
2005.05.15|
5페이지| 1,000원|
조회(1,339)
-
미리보기
-
-
[자료구조] [프로그램 소스] ★ 중위표현식을 후위표현식으로 바꾸는 소스 ★
평가A좋아요
-
#include #include #include #define MAX_STACK_SIZE 100#define MAX_EXPR_SIZE 100typedef enum {lparen, rparen, plus, minus, times, divide, mod, eos, operand} precedence;precedence stack[MAX_STACK_SIZE];char expr[MAX_EXPR_SIZE];int isp[]={0, 19, 12, 12, 13, 13, 13, 0};int icp[]={20, 19, 12, 12, 13, 13, 13, 0};void postfix(void);precedence deletion(int *top);void add(int *top, precedence item);void print_token(precedence token);void main(){printf("Input the expression : ");gets(expr);postfix();}precedence deletion(int *top){precedence token;if (*top == -1) {printf("Stack is empty. n");exit(1);}token = stack[(*top)];(*top)--;return token;// return stack[(*top)--];}void add(int *top, precedence item){if (*top >= MAX_STACK_SIZE-1) {printf("Stack is full. n");exit(1);}++(*top); stack[*top] = item;// stack[++*top] = item;}void print_token(precedence token){if (token == plus) printf("+");else if (token == minus) printf("-");else if (token == times) printf("*");else if (token == divide) printf("/");else if (token == mod) printf("%");}precedence get_token(char *symbol, int *n){*symbol = expr[(*n)++];switch (*symbol) {case '(' : return lparen;case ')' : return rparen;case '+' : return plus;case '-' : return minus;case '*' : return times;case '/' : return divide;case '%' : return mod;case '