zoukankan      html  css  js  c++  java
  • 初学数据结构四

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 struct _Node
     4 {
     5 int data;
     6 struct _Node *next;
     7 };
     8 typedef struct _Node node_t;
     9 typedef struct _Linklist
    10 {
    11 node_t *phead;
    12 node_t *ptail;
    13 int len;
    14 }Linklist;
    15 static node_t *GetNode(int i)
    16 {
    17 node_t *pNode;
    18 pNode=(node_t*)malloc(sizeof(node_t));
    19 if(!pNode)
    20 {
    21 prinf("Error, the memory is not enough!
    ");
    22 exit(-1);
    23 }
    24 pNode->data=i;
    25 pNode->next=NULL;
    26 return pNode;
    27 }
    28 void init_list(Linklist *plist)
    29 {
    30 node_t *p;
    31 p=GetNode(1);
    32 plist->phead=p;
    33 plist->ptail=p;
    34 p->next=plist->phead;
    35 plist->len=1;
    36 }
    37 static void Create_List(Linklist*plist,int n)
    38 {
    39 int i=0;
    40 node_t *pNew;
    41 for(i=2;i<=n;i++)
    42 {
    43 pNew=GetNode(i);
    44 plist->tail->next=pNew;
    45 plist->tail=pNew;
    46 pNew->next=plist->phead;
    47 plist->len++;
    48 }
    49 printf("Completethe e-way circulation chain table the");
    50 }
    51 void Print_List(Linklist* plist)
    52 {
    53 node_t *pCur=plist->head;
    54 do
    55 {
    56 printf("THe %d person.
    ",plist->data);
    57 pCur=pCur->next;
    58 }while(pCur!=plist->phead);
    59 printf("The length of the list:%d
    ",plist->len);
    60 }
    61 void joseph(Linklist *plist,int m)
    62 {
    63 node_t *pPre=plist->ptail;
    64 node_t *pCur=plist->phead;
    65 int i;
    66 while(plist->len!=1)
    67 {
    68 i=0;
    69 while(plist->len!=1)
    70 {
    71 i=0;
    72 while(i<m-1)
    73 {
    74 pPre=pPre->next;
    75 i++;
    76 }
    77 pCur=pPre->next;
    78 pPre->next=pCur->next;
    79 free(pCur);
    80 plist->len--;
    81 }
    82 printf("The last one is:",pPre->data);
    83 }
    84 int main()
    85 {
    86 int n=0;
    87 printf("Please input the length of the Circle list:");
    88 scanf_s(%d,&m);
    89 Linklist pList;
    90 init_list(&pList);
    91 Create_List(&pList,n);
    92 Print_List(&pList);
    93 joseph(&pList,m);
    94 system("pause");
    95 return 0;
    96 }
  • 相关阅读:
    ActiveReports 9实战教程(1): 手把手搭建环境Visual Studio 2013 社区版
    分享产品发布的10条经验
    Mobile first! Wijmo 5 + Ionic Framework之:Hello World!
    Java知识回顾 (14)网络编程
    Java知识回顾 (13)序列化
    idea下java项目的打包与使用
    Java知识回顾 (12) package
    Java知识回顾 (11) 异常处理
    创建表时 ORA-00955: 名称已由现有对象使用
    工作笔记—hibernate之QueryCriteria
  • 原文地址:https://www.cnblogs.com/Zblogs/p/3351341.html
Copyright © 2011-2022 走看看