欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

C語言中字符串實(shí)現(xiàn)正序與逆序?qū)嵗斀?/h1>
來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語言|點(diǎn)擊: 次

C語言中字符串實(shí)現(xiàn)逆序?qū)嵗斀?/strong>

字符串逆序和正序的實(shí)現(xiàn)代碼:

#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

#include <malloc.h>

#include <string.h>

/*定義*/

typedef struct node

{

 char c;

 struct node *llink,*rlink;

}stud;

/*建立鏈表*/

stud * creat(void)

{

 stud *p,*h,*s;

 char a;

 if((h=(stud *)malloc(sizeof(stud)))==NULL)

 {

  printf("不能分配內(nèi)存空間!");

  exit(0);

 }

 h->c = 0;

 h->llink=NULL;

 h->rlink=NULL;

 p=h;

 while(1)

 {

a = getchar();

if(a=='\n')

break;

  if((s= (stud *) malloc(sizeof(stud)))==NULL)

  {

   printf("不能分配內(nèi)存空間!");

   exit(0);

  }

  p->rlink=s;

  

  s->c =a;

  s->llink=p;

  s->rlink=NULL;

  p=s;

 }

 h->llink=s;

 p->rlink=h;

 return(h);

}

/*正序*/

void print1(stud *h)

{

 stud *p;

 p=h->rlink;

 printf("字符串(正序):");

 while(p!=h)

 {

  printf("%c",p->c);

  p=p->rlink;

 }

 printf("\n");

}

/*逆序*/

void print2(stud *h)

{

 stud *p;

 p=h->llink;

 printf("字符串(逆序):");

 while(p!=h)

 {

  printf("%c",p->c);

  p=p->llink;

 }

 printf("\n");

}

/*釋放*/

void free_stud(stud *h)

{

 stud *p,*q;

 p=h->llink;

 while(p!=h)

 {

  q=p;

  p=p->llink;

  free(q);

 }

 free(h);

}

/*主函數(shù)*/

int main()

{

 stud *head=NULL;

 head=creat();

 print1(head);

 print2(head);

 free_stud(head);

 return 0;

}

實(shí)現(xiàn)效果圖:

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有