C language (data structures, DEVFORGE learn programming community)

1, run-length encoding compression algorithm

 1 #include<stdio.h>
 2 #include <string.h>
 3 #define N 100
 4 
 5 int main()
 6 {    
 7     char s[N] = "", t[N] = "", ch;
 8     gets(s);
 9     
10     int count = 0, index = 0;
11     for(int i=0; s[i]; ++i)
12     {    
13         if(!count)
14             ch = s[i];
15         count++;
16         if(ch!=s[i+1] || count==9){
17             t[index++] = count+'0';
18             t[index++] = ch;            
19             count=0;            
20         }
21     }
22     printf("%s",t); 
23     return 0;
24 }

2, create a list traversal workers

 1 #include <stdio.h>
 2 #include <malloc.h>
 3 #include <string.h>
 4 #define N 100
 5 
 6 typedef struct node EMPLOYEE,*LIST;
 7 struct node{ 
 8     int num;
 9     LIST next;
10 };
11 
12 void Insert(LIST head,int num)
13 {    
14     LIST p = head, s;
15     s = (LIST)malloc( sizeof(The EMPLOYEE));
 16      S-> NUM = NUM; // to assign p 
. 17      
18 is      the while ! (P-> Next = NULL && S-> NUM> = p-> next-> NUM)
 . 19          p = p-> Next;
 20 is      // connector 
21 is      S-> Next = p-> Next; // if s max, p-> Next = NULL 
22 is      p-> Next = s;  
 23 is  }
 24  
25  the LIST the Create ()
 26 is  {
 27      // creating the first node 
28      the LIST head = (the LIST) the malloc ( the sizeof (the EMPLOYEE));
 29      head-> Next = NULL;
30     
31     int n,num;
32     scanf("%d",&n);
33     //插入n个职工号
34     while(n--)
35     {
36         scanf("%d",&num);
37         Insert(head,num);
38     }
39     return head;
40 }
41 
42 void Print(LIST head)
43 {    
44     LIST p = head;
45     while(p->next != NULL)
46     {
47         p = p->next;
48         printf("%d ",p->num);
49     }   
50 }
51 
52 int main()
53 {    
54     LIST head = Create();
55     Print(head);    
56     return 0;
57 }

3, Thesis Print

 

Guess you like

Origin www.cnblogs.com/GoldenEllipsis/p/11649287.html