c언어 이중연결리스트에서 맨앞 맨뒤 위치지정 삽입 삭제 코드좀 알려주세...

c언어 이중연결리스트에서 맨앞 맨뒤 위치지정 삽입 삭제 코드좀 알려주세...

작성일 2018.05.02댓글 1건
    게시물 수정 , 삭제는 로그인 필요

#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;
  }
}


아니면 새로운 방식이라도 좀 알려주세요 바로 채택!



profile_image 익명 작성일 -

#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;

top = (struct Node *)malloc(sizeof(struct Node));//맨앞을 가르키는 역활 데이터는 저장않함
bottom = (struct Node *)malloc(sizeof(struct Node)); //맨뒤 데이터는 저장 않함

top->next = bottom;
bottom->prev = top;//서로 가르키게


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->data = data;//입력한 데이터 저장

node->next = top->next;
top->next->prev = node;

node->prev = top;
top->next = node;//top다음에 node 삽입 하기
break;
case 2:
break;
case 3:
break;
}
size++;
break;

case 2:
break;
case 3:
break;
case 4://리스트 전체 출력
node = top->next;

while (node != bottom)
{
printf("%d->", node->data);
node = node->next;
}
printf("\n");
break;
case 5:
return 0;
}
}
}

영어 좀 알려주세

... 알려주십시오 영어 좀 알려주세요 동사... 맨 앞에서 의문문을 이끌거나 간접의문문을 만들 때 사용됩니다. 관계부사는 글과 글을 연결시...

C언어 이중연결리스트 원소삽입

... C언어로 어떻게 바꿔서 작성해야되는질 모르겠습니다 소스코드에다 해석 달아서 알려주세요.....이중연결리스트 삽입입니...