데이터 구조 알고리즘 필기 lesson 6 순환 링크 1
                                            
 3979 단어  데이터 구조알고리즘 학습 노트
                    
단일 체인 표 에서 단말기 결점 의 지침 을 빈 지침 에서 가리 키 는 머리 결점 으로 바 꾸 면 전체 단일 체인 표 가 하나의 고 리 를 형성 하 게 된다. 이런 머리 와 꼬리 가 연 결 된 단일 체인 표 는 단일 순환 체인 표 라 고 부른다.
순환 링크 와 싱글 링크 의 주요 차이
순환 적 으로 빈 링크 를 판단 하 는 조건 에서 head - > next 가 null 인지, head - > next 가 head 인지 여 부 를 판단 합 니 다.
초기 화
typedef struct CLinkList
{
        int data;
        struct CLinkList  *next;
}
void ds_init( node **pNode)
{
        int item;
        node *temp;
        node *target;
        printf ("      ");
        while(1)
         {
            scanf("%d",&item);
            fflush(stdin);
             if(item==0)
                return; 
             if((*pNode)==NULL)
              {
                 *pNide = (node*)malloc (sizeof(struct CLinkList));
                   if(!(*pNode))
                    exit(0);
                 (*pNode)->data = item;
                 (*pNode)->next = *pNode;
              }
         else
        {
                for(target=(*pNode);target->next !=(*pNode); target=target->next);
                temp= (node*)malloc (sizeof(struct CLinkList));
                if(!temp)
                 exit(0);
                temp->data = item;
                temp->next= *pNode;
                target->next = temp;
             }
        }
   }  끼어들다
void ds_insert(node**pNode , int i)
{
    node *temp;
    node *target;
    node *p;
    int item;
    int j =1;
    printf("   :");
    scanf("%d",&item);
    if(i==1)
    {
      temp = (node*)malloc(sizeof(struct CLinkList));
      if (!temp)
       exit(0);
      temp -> data = item;
      for (target = (*pNode);target->next ! = (*pNode);target= target->next);
      temp -> next = (*pNode);
      target->next = temp;
      *pNode = temp;
    }
    else 
     {
        target = *pNode ; 
        for (; jnext;
        temp = (node *)malloc (sizeof(struct CLinkList));
        if(!temp)
          exit(0);
        temp ->data = item;
         
        p = target ->next;
        target->next = temp;
        temp ->next =p ;
     }  삭제
 void ds_delete(node **pNode , int i)
{
    node * target;
    node* temp;
    int j = 1;
    if(j==1)
   {
     for (target = (*pNode);target->next ! = (*pNode);target= target->next);
     temp = *pNode;
     *pNode = (*pNode)->next;
     target->next = *pNode;
     free(temp);
    }
  else
   {      target = *pNode;
    for(; jnext;
    temp =target ->next;
    target->next = temp ->next;
    free(temp);
   }
}   결점 이 있 는 위치 로 되돌아가다
int ds_search(node *pNode, int elem)
{
    node *target;
    int  i =1;
    for (target = pNode;target->data! = elem&& target->next != pNode;++i)
     {
        target = target->next;
     }
      if(target->next == pNode)
          return 0 ; 
       else 
          return 1;
}  조세 프 문제
 #include
 #include 
typedef  node
{
   int data;
   struct node* next;
}node;
node *create (int n)
{
    node *p = NULL, *head;
    head = (node*)malloc (sizeof(node));
    p =head;
    node *s;
    int i = 1;
    if(0!=n)
     {
         while(i<=n)
      {
         s =(node*)malloc (sizeof(node));
         s->data = i++;
         p->next = s ;
         p = s;
      }
         s->next = head->next;
     }
     free (head);
    return s->next;
}
  
int main()
{
     int n =41;
     int m =3;
     int i ;
     node *p =create(n);
     node *temp;
     m%=n;
   while(p != p->next)
    {
       for (i=1;inext ;
       }
      printf("%d->" , p->next->data);
      temp = p->next;
      p->next = temp->next;
      free(temp);
      p = p->next;
    }
  printf("%d
",p->data);
  return 0;
}     이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
정수 반전Udemy 에서 공부 한 것을 중얼거린다 Chapter3【Integer Reversal】 (예) 문자열로 숫자를 반전 (toString, split, reverse, join) 인수의 수치 (n)가 0보다 위 또는 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.