022. C語言基礎(chǔ)

//   211.c
#include<stdio.h>
struct node
{
   int num;
   struct node *next;
};
void main()
{
   struct node *p;
}
//   212.c
#include<stdio.h>
struct node
{
   char *name;
   char sex;
   int score;
};
void main()
{
   struct node x[5]=
   {"001",'M',98,
    "002",'W',89,
    "003",'M',97,
    "004",'M',79,
    "005",'W',69},t;
   int i,j;
   for(i=0;i<4;i++)
     for(j=i+1;j<5;j++)
       if(x[i].score<x[j].score)
       {
          t=x[i];x[i]=x[j];x[j]=t;
       }
    for(i=0;i<5;i++)
      printf("%s:%c,%d\n",x[i].name,x[i].sex,x[i].score);
    getch();

}
//   213.c
#include<stdio.h>
struct node
{
   char a[20];
   int num;

};
void main()
{
   struct node x[5]={"x001",90,
                     "x002",80,
                     "x003",97,
                     "x004",99,
                     "x005",87},*p,*q,t;
   for(p=x;p<x+4;p++)
     for(q=p+1;q<x+5;q++)
     {
        if((*p).num>(*q).num)
        {
            t=*p;*p=*q;*q=t;
        }
     }
   for(p=x;p<x+5;p++)
     printf("%s:%d\n",(*p).a,(*p).num);
   getch();

}
//   214.c
#include<stdio.h>
struct node
{
   char a[20];
   int num;

};
void main()
{
   struct node x[5]={"x001",90,
                     "x002",80,
                     "x003",97,
                     "x004",99,
                     "x005",87},*p,*q,t;
   for(p=x;p<x+4;p++)
     for(q=p+1;q<x+5;q++)
     {
        if(p->num>q->num)  //(*p).num等價于p->num
        {
            t=*p;*p=*q;*q=t;
        }
     }
   for(p=x;p<x+5;p++)
     printf("%s:%d\n",p->a,p->num);
   getch();

}
//    215.c
#include<stdio.h>
struct node
{
   char a[20];
   int num;
};
void fun(struct node x[],char name[],int n)
{       //結(jié)構(gòu)體數(shù)據(jù)類型變量作為函數(shù)的參數(shù)
    int i;
    for(i=0;i<n;i++)
      if(strcmp(x[i].a,name)==0){x[i].num++;break;}
}
void main()
{
   struct node x[3]={"x001",0,
                     "x002",0,
                     "x003",0};
   int i;
   char name[20];
   for(i=0;i<5;i++)
   {
       scanf("%s",name);
       fun(x,name,3);

   }
   for(i=0;i<3;i++)
     printf("%s:%d\n",x[i].a,x[i].num);
   getch();
}
//   216.c
#include<stdio.h>
struct node
{
   int num; //普通成員變量
   struct node *next; //指針成員變量
};
void main()
{
   struct node a={1},b={2},c={3},*p;
   a.next=&b;
   b.next=&c;
   c.next=&a;
   p=&a;
   while(p!=NULL)
   {
      printf("%3d",p->num);
      p=p->next;
   }
   getch();
}
//    217.c
#include<stdio.h>
//靜態(tài)開辟10個內(nèi)存單元,創(chuàng)建鏈表.
struct node
{
   int num;
   struct node *next;
};
void main()
{
   struct node a[10],*p;
   int i;
   for(i=0;i<10;i++)
   {
      a[i].num=i+1;
      if(i<9)a[i].next=&a[i+1];
      else a[i].next=NULL;
   }
   p=a;
   while(p!=NULL)
   {
      printf("%3d",p->num);
      p=p->next;
   }
   getch();
}
//    218.c
#include<stdio.h>
//動態(tài)開辟含有5個結(jié)點的鏈表
#include<malloc.h>
struct node
{
   int num;
   struct node *next;
};
void main()
{
   struct node *p1,*p2,*head;
   int i=0;
   head=p1=p2=(struct node *)malloc(sizeof(struct node));
   scanf("%d",&head->num);
   i++;
   while(i<5)
   {
      p2=p1;
      p1=(struct node *)malloc(sizeof(struct node));
      scanf("%d",&p1->num);
      p2->next=p1;
      i++;
   }
   p1->next=NULL;
   while(head!=NULL)
   {
      printf("%3d",head->num);
      head=head->next;
   }
   getch();
}
//    219.c
#include<stdio.h>
#include<malloc.h>
struct node
{
   int num;
   struct node *next;
};
void putfun(struct node *head)
{
   while(head!=NULL)
   {
     printf("%3d",head->num);
     head=head->next;
   }
}
struct node *fun(int n)
{
   struct node *head,*p1,*p2;
   int i=0;
   if(n==0)return NULL;
   head=p1=p2=(struct node *)malloc(sizeof(struct node));
   scanf("%d",&head->num);
   i++;
   while(i<n)
   {
      p2=p1;
      p1=(struct node *)malloc(sizeof(struct node));
      scanf("%d",&p1->num);
      p2->next=p1;
      i++;
   }
   p1->next=NULL;
   return head;
}
void main()
{
   struct node *head;
   head=fun(5);
   putfun(head);
   getch();
}
//   220.c
#include<stdio.h>
#include<malloc.h>
struct node
{
   int num;
   struct node *next;
};
void putfun(struct node *head)
{
   while(head!=NULL)
   {
      printf("%3d",head->num);
      head=head->next;
   }
}
struct node *fun(int n)
{
    struct node *m,*p;
    if(n==0)return NULL;
    m=NULL;
    while(n)
    {
       p=(struct node *)malloc(sizeof(struct node));
       p->num=n;
       p->next=m;
       m=p;
       n--;
    }
    return p;
}
struct node *fxfun(struct node *head)
{
    struct node *p1,*p2,*p3,*m;
    if(head->next==NULL)return head;
    m=NULL;
    p2=head;
    p1=p2->next;
    p3=p1->next;
    while(p3!=NULL)
    {
      p2->next=m;
      p1->next=p2;
      m=p2;
      p2=p1;
      p1=p3;
      p3=p3->next;
    }
    p2->next=m;
    p1->next=p2;
    return p1;
}
struct node *delfun(struct node *p,int n)
{
    struct node *head,*m;
    head=m=p;
    if(p->num==n){head=head->next;free(p);return head;}
    while(p!=NULL&&p->num!=n)
    {
       m=p;
       p=p->next;
    }
    if(p!=NULL)m->next=p->next;
    free(p);
    return head;
}
void main()
{
   struct node *head;
   int n;
   scanf("%d",&n);
   head=fun(n);
   putfun(head);
   head=fxfun(head);
   printf("\nfanxu after's xiao guo is:\n");
   putfun(head);
   printf("\nplease input a's delnum:");
   scanf("%d",&n);
   head=delfun(head,n);
   printf("\ndelete after's xiao guo is:\n");
   putfun(head);
   getch();
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末镀层,一起剝皮案震驚了整個濱河市谅摄,隨后出現(xiàn)的幾起案子服猪,更是在濱河造成了極大的恐慌燕刻,老刑警劉巖涮毫,帶你破解...
    沈念sama閱讀 217,509評論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件畴蹭,死亡現(xiàn)場離奇詭異最筒,居然都是意外死亡朗恳,警方通過查閱死者的電腦和手機(jī)湿颅,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,806評論 3 394
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來粥诫,“玉大人油航,你說我怎么就攤上這事』辰” “怎么了谊囚?”我有些...
    開封第一講書人閱讀 163,875評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長执赡。 經(jīng)常有香客問我镰踏,道長,這世上最難降的妖魔是什么沙合? 我笑而不...
    開封第一講書人閱讀 58,441評論 1 293
  • 正文 為了忘掉前任奠伪,我火速辦了婚禮,結(jié)果婚禮上首懈,老公的妹妹穿的比我還像新娘绊率。我一直安慰自己,他們只是感情好究履,可當(dāng)我...
    茶點故事閱讀 67,488評論 6 392
  • 文/花漫 我一把揭開白布滤否。 她就那樣靜靜地躺著,像睡著了一般挎袜。 火紅的嫁衣襯著肌膚如雪顽聂。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,365評論 1 302
  • 那天盯仪,我揣著相機(jī)與錄音紊搪,去河邊找鬼。 笑死全景,一個胖子當(dāng)著我的面吹牛耀石,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播爸黄,決...
    沈念sama閱讀 40,190評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼滞伟,長吁一口氣:“原來是場噩夢啊……” “哼揭鳞!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起梆奈,我...
    開封第一講書人閱讀 39,062評論 0 276
  • 序言:老撾萬榮一對情侶失蹤野崇,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后亩钟,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體乓梨,經(jīng)...
    沈念sama閱讀 45,500評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,706評論 3 335
  • 正文 我和宋清朗相戀三年清酥,在試婚紗的時候發(fā)現(xiàn)自己被綠了扶镀。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,834評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡焰轻,死狀恐怖臭觉,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情辱志,我是刑警寧澤蝠筑,帶...
    沈念sama閱讀 35,559評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站荸频,受9級特大地震影響菱肖,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜旭从,卻給世界環(huán)境...
    茶點故事閱讀 41,167評論 3 328
  • 文/蒙蒙 一稳强、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧和悦,春花似錦退疫、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,779評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至馍忽,卻和暖如春棒坏,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背遭笋。 一陣腳步聲響...
    開封第一講書人閱讀 32,912評論 1 269
  • 我被黑心中介騙來泰國打工坝冕, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人瓦呼。 一個月前我還...
    沈念sama閱讀 47,958評論 2 370
  • 正文 我出身青樓喂窟,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子磨澡,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,779評論 2 354

推薦閱讀更多精彩內(nèi)容