c언어 이중연결리스트에서 맨앞 맨뒤 위치지정 삽입 삭제 코드좀 알려주세...
-
게시물 수정 , 삭제는 로그인 필요
#include<stdio.h>
#include<stdlib.h>
typedef int Element;
typedef struct Node{
Element data; //데이터 필드
struct Node* prev; //선행노드
struct Node* next; //후속노드
}; Node;
// Node org;
int main(void)
{
struct Node *top = NULL, *bottom = NULL;
int size = 0;
while (1)
{
int menu, pos, data;
struct Node *node, *tmp;
int i;
printf("메뉴를 선택하세요.\n\t1. 노드 추가\n\t2. 노드 삭제\n\t3. 노드 검색\n\t4. 노드 출력\n\t5. 종료\n메뉴 : ");
while (scanf_s("%d", &menu) != 1)
{
printf("숫자만 입력해주세요.");
}
switch (menu)
{
case 1:
printf("노드를 추가할 위치를 선택하세요.\n\t1. 맨 앞\n\t2. 맨 뒤\n\t3. 위치 지정\n\t4. 취소\n위치 : ");
while (scanf_s("%d", &pos) != 1)
{
printf("숫자만 입력해주세요. >> ");
}
switch (pos)
{
case 1:
printf("추가할 숫자를 입력하세요 : ");
while (scanf_s("%d", &data) != 1)
{
printf("숫자만 입력해주세요. >> ");
}
node = (struct Node *)malloc(sizeof(struct Node)); //노드생성
node-> 여기서 뭐해야할지 모르겠어요.
}
size++;
break;
}
}
아니면 새로운 방식이라도 좀 알려주세요 바로 채택!
#include<stdio.h>
#include<stdlib.h>
typedef int Element;
typedef struct Node{
Element data; //데이터 필드
struct Node* prev; //선행노드
struct Node* next; //후속노드
}; Node;
// Node org;
int main(void)
{
struct Node *top = NULL, *bottom = NULL;
int size = 0;
while (1)
{
int menu, pos, data;
struct Node *node, *tmp;
int i;
printf("메뉴를 선택하세요.\n\t1. 노드 추가\n\t2. 노드 삭제\n\t3. 노드 검색\n\t4. 노드 출력\n\t5. 종료\n메뉴 : ");
while (scanf_s("%d", &menu) != 1)
{
printf("숫자만 입력해주세요.");
}
switch (menu)
{
case 1:
printf("노드를 추가할 위치를 선택하세요.\n\t1. 맨 앞\n\t2. 맨 뒤\n\t3. 위치 지정\n\t4. 취소\n위치 : ");
while (scanf_s("%d", &pos) != 1)
{
printf("숫자만 입력해주세요. >> ");
}
switch (pos)
{
case 1:
printf("추가할 숫자를 입력하세요 : ");
while (scanf_s("%d", &data) != 1)
{
printf("숫자만 입력해주세요. >> ");
}
node = (struct Node *)malloc(sizeof(struct Node)); //노드생성
node-> 여기서 뭐해야할지 모르겠어요.
}
size++;
break;
}
}
아니면 새로운 방식이라도 좀 알려주세요 바로 채택!