This presentation is the property of its rightful owner.
Sponsored Links
1 / 145

计算机实习 PowerPoint PPT Presentation


  • 178 Views
  • Uploaded on
  • Presentation posted in: General

计算机实习. 第 2 讲. 复习. 结构体 struct 结构体类型名 { 类型 成员 1; 类型 成员 2; 类型 成员 n; };. 复习. 结构体 struct 结构体类型名 { 类型 成员 1; 类型 成员 2; 类型 成员 n; } 变量 1, 数组 1;. 复习. #include "stdio.h" #include "math.h" struct point { float x; float y; };. 复习.

Download Presentation

计算机实习

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


4390620

2


4390620

struct

{ 1;

2;

n;

};


4390620

struct

{ 1;

2;

n;

}1,1;


4390620

#include "stdio.h"

#include "math.h"

struct point

{

float x;

float y;

};


4390620

void input(struct point a[])

{

int i;

for(i=0;i<2;i++)

{printf("%d\n",i+1);

scanf("%f%f",&a[i].x,&a[i].y);

}

}


4390620

void midpoint(struct point a[])

{

int i;struct point m;m.x=0;m.y=0;

for(i=0;i<2;i++)

{m.x=m.x+a[i].x;

m.y=m.y+a[i].y;}

m.x=m.x/2;m.y=m.y/2;

a[2].x=m.x;a[2].y=m.y;

}


4390620

float dis(struct point a[])

{

int i;float s;struct point m;m.x=a[0].x;m.y=a[0].y;

{m.x=m.x-a[1].x;m.y=m.y-a[1].y;}

s=sqrt(m.x*m.x+m.y*m.y);

return s;

}


4390620

main()

{

struct point a[3];

input(a);

printf(" 1%f %f 2%f %f\n",a[0].x,a[0].y,a[1].x,a[1].y);

midpoint(a);

printf(" %f %f \n",a[2].x,a[2].y);

printf("%f\n",dis(a));

}


4390620

#include "stdio.h"

#include "string.h"

struct data

{ int month; int day; int year; };

struct stud

{ char name[20];

char tele[12];

char zip[7];

struct data birthday;

char addre[30];

};

struct stud stud1[30]={"liming","1331187907","210020",3,14,1988,"beijing","chaening","13789087907","260020",8,14,1980,"tianjing","being","13678987907","710020",9,14,1990,"nanjing"};


4390620

main()

{ int k,i,j,n=3;

struct stud temp;

for ( i = 0; i < n-1; i++)

{ k = i;

for (j= i+1;j<n; j++)

if (strcmp(stud1[j].name,stud1[k].name)<0)

k =j;

temp= stud1[i];

stud1[i]= stud1[k];

stud1[k]= temp;

}

printf(" \n");

for(i=0;i<3;i++)

printf("%10s%12s%8s %2d-%2d-%4d %15s\n",stud1[i].name,stud1[i].tele,stud1[i].zip,stud1[i].birthday.month,stud1[i].birthday.day,stud1[i].birthday.year,stud1[i].addre);

}


4390620

1.

FILE *;

2.

if((=fopen("file9_3.txt","w"))==NULL)

{ printf("%s\n","e:\\file9_3.txt");

exit(1);

}


4390620

3.

fprintf(,"%5d ",b[i]);

4.

fclose(fp);


4390620

,diy2.dat)


4390620

#include "stdio.h"

#include "string.h"

struct staff

{

int num;

char name[20];

float basic_wage;

float percentage;

float bonus;

float real_wages;

float wages_should;

}sp[200]={901,"",432,120,66,0,0,902,"",488,123,75,0,0,903,"",423,240,24,0,0,904,"",356,789,72,0,0,905,"",530,765,114,0,0,906,"",488,456,87,0,0,907,"",530,345,102,0,0};

FILE *fp3;


4390620

void file(struct staff a[],int n)

{ int i;FILE *fp3;

if((fp3=fopen("diy2.dat", "w"))==NULL)

{

printf("Open error \n");exit(0);

}

for(i=0;i<n;i++)

{

fprintf(fp3,"%d,%s,%f,%f,%f,%f,%f",a[i].num,a[i].name,a[i].basic_wage,a[i].percentage,a[i].bonus,a[i].real_wages,a[i].wages_should);

}

fclose(fp3);

}


4390620

int max(struct staff a[],int n)

{

int imax=0,i;

for(i=0;i<n;i++)

if(a[i].basic_wage>a[imax].basic_wage) imax=i;

return imax;

}


4390620

int min(struct staff a[],int n)

{

int imin=0,i;

for(i=0;i<n;i++)

if(a[i].basic_wage<a[imin].basic_wage) imin=i;

return imin;

}


4390620

void comput(struct staff a[],int n)

{

int i;

for(i=0;i<n;i++)

{a[i].wages_should=a[i].basic_wage+a[i].percentage+a[i].bonus;

a[i].real_wages=a[i].wages_should-a[i].wages_should*0.1;

}

}


4390620

float ave(struct staff a[],int n)

{

int i;float ave=0;

for(i=0;i<n;i++)

ave=ave+a[i].basic_wage;

ave=ave/n;

return ave;

}


4390620

main()

{ int m=7;

comput(sp,m);

printf(" %f %f %f\n",sp[max(sp,m)].basic_wage,sp[min(sp,m)].basic_wage,ave(sp,m));

file(sp,m);

}


4390620


4390620


4390620

  • 53:

  • struct stud

  • {int no;

  • char name[16];

  • float mark[3];

  • float ave;

  • };

  • 5AA.dat


4390620

void file(struct stud a[],int n)

{ int i;

FILE *fp3;

if((fp3=fopen(AA.dat", "w"))==NULL)

{

printf("Open error \n");exit(0);

}

for(i=0;i<n;i++)

{

fprintf(fp3,"%d,%s,%f,%f,%f,%f\\n",a[i].num,a[i].name,a[i]. mark[0],a[i].mark[1],a[i].mark[2].a[i].ave);

}

fclose(fp3);

}


4390620


4390620

3

3

1

3

2

4


4390620

0

...

2000

2001

2002

2003

2005

...

-----

: int i;

float k;

i

k


4390620

...

i

2000

10

2001

2002

2003

i_pointer

2004

2005

()

2006

...

2000


4390620

  • [] *

int*p1,*p2;

float *q ;

static char *name;

*

1int *p1, *p2; int *p1, p2;

2p1,p2 ,*p1,*p2

3

4


4390620

...

i

2000

10

2001

2002

2003

i_pointer

2004

2000

2005

2006

...

&*

:

: 2

:

:

: 2

:

i_pointer &i &(*i_pointer)

i *i_pointer *(&i)

i_pointer=&i=&(*i_pointer)

i=*i_pointer =*(&i)

i_pointer-----

*i_pointer----

&i_pointer---


4390620

1

  • #include <stdio.h>

  • int main( )

  • { int i = 100, j=200;

  • int *p;

  • p = &i; //ip

  • printf("&i=%d *(&i)=%d\n", &i, *(&i));

  • printf(" p=%d *p =%d\n\n", p, *p);

  • p = &j; //jp

  • printf("&j=%d *(&j)=%d\n", &j, *(&j));

  • printf(" p=%d *p =%d\n", p, *p);

  • return 0;

  • }

||


4390620

  • --

int i;

int *p=&i;

int i;

int *p=&i;

int *q=p;


4390620

2

...

i

2000

10

2001

2002

2003

p

2004

2005

2006

...

  • main( )

  • { int i=10;

  • int *p;

  • *p=i;

  • printf(%d,*p);

  • }


4390620

    • datatype *p; pDS, p n = DS n*sizeof(datatype)

    • p<=&a[3]


4390620


4390620

...

main()

{ int *p1,*p2,*p,a,b;

scanf("%d,%d",&a,&b);

p1=&a; p2=&b;

if(a<b)

{ p=p1; p1=p2; p2=p;}

printf("a=%d,b=%d\n",a,b);

printf("max=%d,min=%d\n",*p1,*p2);

}

2008

2000

p1

2006

2002

2006

2004

p2

p

b

a

5

2006

9

2008

...


4390620

int a[10];

a[i]

a+i a[i]

*(a+i)a[i]


4390620

  • int a[5]

    int *p

    p=&a[0]

    p=a;

  • *pia[i]


4390620

p[0]

a[0]

a[0]

a[0]

*p

*a

*(p+1)

*(a+1)

p[1]

a[1]

a[1]

a[1]

*(p+2)

*(a+2)

p[2]

a[2]

a[2]

a[2]

p

a

a[3]

a[3]

p+1

a+1

p+2

a+2

a[9]

p[9]

a[9]

*(a+9)

*(p+9)

a[9]

...

...

p+9

a+9

[]

a[i] *(a+i)

a[i] p[i] *(p+i) *(a+i)


4390620

pa

a[0]

1

a[1]

2

a[2]

3

a[3]

4

a[4]

5

main()

{ int a[5],*pa,i;

for(i=0;i<5;i++)

a[i]=i+1;

pa=a;

for(i=0;i<5;i++)

printf("*(pa+%d):%d\n",i,*(pa+i));

for(i=0;i<5;i++)

printf("*(a+%d):%d\n",i,*(a+i));

for(i=0;i<5;i++)

printf("pa[%d]:%d\n",i,pa[i]);

for(i=0;i<5;i++)

printf("a[%d]:%d\n",i,a[i]);

}


4390620

  • p++; ++p; /*p */

  • p--; --P; /*p */

  • p+n; /*pn */

  • p-n; /*pn */

  • p-q; /*pqpq,qp*/


4390620

pintp=&a[0];

p+1 a[1]

int a[10];

int *p=&a[2];

p++;

*p=1;

int a[10];

int *p1=&a[2];

int *p2=&a[5];

p2-p1=3;


4390620


4390620

string

string[0]

I

string[1]

string[2]

l

string[3]

o

string[4]

v

string[5]

e

string[6]

string[7]

C

string[8]

h

string[9]

i

string[10]

n

string[11]

a

string[12]

!

string[13]

\0

main( )

{ char string[]=I love China!;

printf(%s\n,string);

printf(%s\n,string+7);

}


4390620

  • char *pstr

  • char *pstr=C language

    char *pstr;

    pstr= "C language"


4390620

string

I

l

o

v

e

C

h

i

n

a

!

\0

main( )

{ char *string=I love China!;

printf(%s\n,string);

string+=7;

while(*string)

{ putchar(string[0]);

string++;

}

}


4390620

main( )

{ char a[80],b[80],*pa,*pb;

pa=a;pb=b;

scanf("%s",pa);

while(*pa!= '\0')

*(pb++)=*(pa++);

*pb=\0;

printf("%s",b) }


4390620

1p++ (p+=1) p

2*p++ ++ *

*(p++)

main()

{ int a[8]={2,4,6,8,10,12,14,16}, i, *p;

for(p=a, i=0; i<8; i++)

printf(%d,, *p++);

}


4390620

p

p

p

3*(p++) *(++p) *p

p 1; p 1 *p

a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7]

*(p++)

2

*(++p)

4

*(++p)*++p

4(*p)++ p 1

a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7]

5

(*p)++

3

4


4390620

3

  • .

  • >

  • *.


4390620

(1) struct date{

int day;

char month;

int year;

} dd, *pd = &dd;

dddd.day

(2)

int a[4] = {0,4,5,13}, *p;

p = &a[2];

printf("++(*p)= %d\n", ++(*p));

printf("*--p=%d\n", *--p);

printf("*p++=%d\n", *p++);

printf("%d\n",a[0]);


4390620

  • bc

  • #include <stdio.h>

  • void main()

  • { int *a[10],b,c;

  • a[0]=&b;

  • *a[0]=5;

  • c=(*a[0])++;

  • printf(%d %d\n,b,c);

  • }


4390620

  • #include <stdio.h>

  • main()

  • { int c1=0,c2=0,c3=0,c4=0;

  • char *p=12395632123378;

  • while (*p)

  • { switch (*p)

  • { case 1 : c1++; break;

  • case 2 : c2++;

  • case 3 : c3++; break;

  • default : c4++;

  • }


4390620

p++;

}

printf(c1=%d c2=%d c3=%d c4=%d\n,c1,c2,c3,c4);

}


4390620

end


4390620

Page112-Line3

5

Page(One) (One) (Two)-Line(Three)

09 0 2 1 1 0 0 0 0 0 0


4390620

#include <stdio.h>

void main()

{ char *table[]={"(Zero)"," (One)"," (Two)"," (Three)"," (Four)",

" (Five)"," (Six)"," (Seven)"," (Eight)"," (Nine)" };

char str1[64],str2[255]*p;

int j,k,nno[10];

for (;;) {

printf("Input:");

gets( 1 ); /**/


4390620

for(k=0;k<10;k++) no[k]=0;

if(strcmp(str1,"end")==0) 2 _ ; /* end */

for(j=k=0;str1[j]!='\0';++j) /* */

{

if ( 3 ) /**/

{ str2[k++]=str1[j];

continue;

}

/**/

n=str1[j]-'0';

no[n]++;

for(p=table[n];*p!='\0';++p)

str2[k++] = 4 ; /* str2 */

}


4390620

str2[k] = 5 ; /* str2 */

printf("%s\n",str2);

for(k=0;k<10;k++) printf("no[%d]=%d\t",k,no[k]);

}

}


4390620

1.int n1=0,n2,*p=&n2,*q=&n1;n2=n1;

A.*p=*q; B p=q;

C.*p=&n1; D.p=*q;


4390620

2.

main()

{ int a[10]={1,2,3,4,5,6,7,8,9,10}, *p=&a[3], *q=p+2;

printf("%d\n", *p + *q);

}

A.16 B.10 C.8 D.6


4390620

3.,______

A.char *sp;*sp="right!";

B.char s[10];s="right!";

C.char s[10];*s="right!";

D.char *sp="right!";


4390620

4.

main

{ char *s=abcde

s+=2

printf%ld\ns

}

A.cde B.cASCII

C.c D.


4390620

5.

main()

{ char s[]="159",*p;

p=s;

printf("%c",*p++);printf("%c",*p++);

}

______

A.15 B.16 C.12 D.59


4390620

6.

#include <stdio.h>

char a[10],*b=a;

a

A.gets(a) B. gets(a[0])

C. gets(&a[0]); D. gets(b)


4390620

7.

#include <stdio.h>

main ()

{ char *p,*q;

p=(char*) malloc (sizeof (char)*20); q=p;

scanf ("%s %s", p, q); printf ("%s %s\n", p, q );

}

abc def<>

A.def def B. abc def

C. abc d D. d d


4390620

8.

void func(int *a,int b[])

{ b[0]=*a+6; }

main()

{ int a,b[5];

a=0; b[0]=3;

func(&a,b); printf("%d \n",b[0]);

}

A. 6 B. 7 C. 8 D. 9


4390620

sa[2]pa[0]s-p


4390620

2___________________

char *p, s[ ]=abcdefgh;

p=s;

printf(%s, p+3);


4390620

3. char*names[]={"Wang","Li","Chen"}printf("Second%sFirst%s", names[1], names[0])_______________________________________

4. in a[5] = { 2, 3, 4, 5, 6 }; int *p = a+2; *p*a[3] _________________

5. int a[5]={1,3,5,7,9},*p=a;++ (*p)


4390620

6. C_____________

#include<stdio.h>

#include<string.h>

void main()

{

char *p[10]={akshj,asas,ayusi,daksfhasf,alsjkfas};

printf(%d\n,strlen(p[4]));

}

/*p[4]*/


4390620

6. C_____________

#include<stdio.h>

#include<string.h>

void main()

{

char *p[10]={akshj,asas,ayusi,daksfhasf,alsjkfas};

printf(%d\n,strlen(p[4]));

}

/*p[4]*/


4390620

7.

#include <stdio.h>

main()

{

int a[]={10,11,12,13,14}, *p, n;

p=&a[0];

n=*(p++);

n+=*(++p);

n+=(*(p+=2))++;

n-=(*(--p))--;

n-=*(--p-1);

printf("n=%d\n",n);

printf("a[2]=%d,a[3]=%d,a[4]=%d\n",a[2],a[3],a[4]);

}


4390620

2.2

#include <stdio.h>

void func(int *x,int y)

{

static k=3;

y=*x+y;

*x=y%k;

k++;

printf("*x=%d,y=%d\n",*x,y);

}

void main()

{

int x=12,y=5;

func(&x,y);

printf("x1=%d,y1=%d\n",x,y);

func(&y,x);

printf("x2=%d,y2=%d\n",x,y);

}


4390620

1.4aezawa


4390620

#include <stdio.h>

void trans( char *dest, char *src )

{ /*srcdest*/

char ch;

while ( ch= )

{

if ( ch>='a' && ch<='z' )

{

ch += 4;

if ( ch > 'z' )

ch =

}

*dest = ch;

dest ++;

}

*dest =

}

*(src++)

'a'+ch-'z'-1;

'\0;


4390620

2.a kb

4.2

#include <string.h>

#include <stdio.h>

copysubstr(char *a, char *b, int k)

{ a=a+k-1;

while ( )

*b++=*a++;

*b='\0';

}

*a!='\0'


4390620

main()

{ int position;

char *str1, *str2;

str1=(char *)malloc(80); /* 80 */

str2= ;

clrscr();

gets(str1);

scanf("%d",&position);

if (position>strlen(str1))

printf(" the value of position is error\n");

else

{ copysubstr( );

printf(" str2=%s\n",str2);

}

}

(char *)malloc(80)

str1,str2,position


4390620

1sortn


4390620

#define N 10

void sort(int *array,int n)

{ int i,j,k,t;

for (i=0;i<n-1;i++)

{ k=i;

for (j=i+1;j<n;j++)

if (*(array+j)>*(array+k)) k=j;

t=*(array+k);*(array+k)=*(array+i);*(array+i)=t;

}

}


4390620

main()

{ int a[N],i;

printf(" enter the array\n");

for (i=0;i<N;i++)

scanf("%d",&a[i]);

sort(a,N);

printf(" the sorted array : \n");

for (i=0;i<N;i++)

printf("%5d",a[i]);

printf("\n");

}


4390620

2. , , , (NULL)


4390620

  • , , , (NULL)

    char *match(char c, char *s)

    { int i=0;

    while(c!=s[i] &&s[i]!='\0') i++;

    return(&s[i]);


4390620

char s1[20]="P4CPU";

char s2[]="DVD+17\"CRT+56KMODEM";

s2[10]='\0';

strcat(s1,s2+3);

puts(s1);


4390620

:

main()

{ int a[ ]={1,2,3,4,5,6}, *p;

p=a; *(p+3)+=2;

printf(%d,%d\n, *p, *(p+3));

}


4390620

3,3..


4390620

-


4390620

3

3

3

1

3

5

2

4

6


4390620

10

AZ81920

10


4390620


4390620

head

head

1

2

3


4390620

struct Train_tag

char Num[8];

char Name[10];

int Weight;

char From[20];

char To[20];

struct Train_tag *next;


4390620

1.


4390620

struct Train_tag

{

charNum[8];/* */

charName[10];/* */

intWeight;/* */

charFrom[20];/* */

charTo[20];/* */

struct Train_tag *next;/* */

}array[10], *head;


4390620

i(0-9) i + 1

void Create( )

{

int i;

head = &array[0];/* */

for(i = 0; i < 10; i++)

{

array[i]

if(i < 9) array[i].next = &array[i+1];

else array[i].next = NULL;

}

}


4390620

head

1

2

10

array[0]

array[1]

array[9]


4390620

2.


4390620

0


4390620

struct Train_tag

{

charNum[8];/* */

charName[10];/* */

intWeight;/* */

charFrom[20];/* */

charTo[20];/* */

struct Train_tag *next;/* */

};

struct Train_tag *head, *p, *q;


4390620

p

q

head

Weight 0 p q head

DX11089

5


4390620

head

q

p

q

Weight 0 p q->next = pnext q

DX11089

5

CY20011

8


4390620

head

q

p

q

DX11089

5

CZ21026

8

CY20011

8


4390620

head

q

Weight 0 q nextNULL q->next = NULL

DX11089

5

AZ81920

10

CY20011

8


4390620

void Create( )

{

int Weight;

head = p = q = NULL;

while( 1 )

{

printf("");

scanf("%d", &Weight);

if(Weight <= 0) break;

p = malloc(sizeof(struct Train_tag));

p->Weight = Weight;

if (head == NULL) head = p; //

else q->next = p; //

q = p; // q

}

if (head != NULL) q->next = NULL;

}


4390620

3.

void Display( )

{

struct Train_tag *p;

p = head;

while(p != NULL)

{

printf("%s, %s, %d, %s, %s\n", p->Num,

p->Name, p->Weight, p->From, p->To);

p = p->next;

}

}


4390620

4.


4390620

p

head

DX11089

5

AZ81920

10

CY20011

8

head = p->next;


4390620

p

q

DX11089

5

AZ81920

10

CY20011

8

q->next = p->next;


4390620

void Delete( )

{

struct Train_tag *p, *q;

if(head == NULL) { printf(""); return; }

p = head;

while((p != NULL) && strcmp(p->To, ""))

{

q = p;

p = p->next;// p

}

if((p != NULL) && !strcmp(p->To, ""))

{

if(p == head)

head = p->next;//

else

q->next = p->next;//

}

}


4390620

5.


4390620

7

head


4390620

struct Train_tag *head; //

struct Train_tag *p; //

struct Train_tag *q; //

struct Train_tag *pNode; //


4390620

pNode

head

head = NULL

pNode

DX11089

5

head = pNode;


4390620

pNode Weight

Weight pNode->Weight <= head->Weight

pNode

pNode->next = head;

head = pNode;


4390620

head

pNode

pNode->next = head;

head = pNode;


4390620

pNode Weight Weight

pNode

qp

q p q

q = head p = head->next

q->Weight < pNode->Weight <= p->Weight

pNode q p


4390620

p

q

p

head

q

pNode

q = p;

p = p->next;

pNode->next = p;

q->next = pNode;


4390620

void Insert(struct Train_tag *pNode)

{

struct Train_tag *p, *q;

//

if(head == NULL)

{

head = pNode;

return;

}

// Weight

if(pNode->Weight <= head->Weight)

{

pNode->next = head;

head = pNode;

return;

}


4390620

//

q = head; p = head->next;

while(p != NULL)

{

if(pNode->Weight <= p->Weight)

break;

else

{

q = p;

p = p->next;

}

}

// pNode(qp)

pNode->next = p;

q->next = pNode;

}


4390620

Weight

while(p != NULL)

{

if(pNode->Weight <= p->Weight)

break;

else

{

q = p;

p = p->next;

}

}

q

p = NULL


4390620

q

head

pNode

p

NULL

NULL

pNode->next = p;

q->next = pNode;


4390620

6.


4390620

p

q

p

p

head

q

q

void Destroy( )

{ struct Train_tag *p, *q;

p = head;

while(p != NULL)

{ q = p;

p = p->next;

free(q);

}

}

head = NULL;

DX11089

5

CZ21026

8

CY20011

8


4390620


4390620

  • (top)(bottom)

  • (LIFO)


4390620

1 Initiate(s)

2 push( s,x)

3 pop ( s)

4 gettop( s)

5 Notempty( s)

6 SETNULL(s)


4390620


4390620

typedef int elemtype;

typedef struct node

{ elemtype data;

struct node *next;

} slnodetype;


4390620

h

h

p

x

...

^

linkstack *PUSHLSTACK(slnodetype *top, elemtype x)

{ slnodetype *p;

pmalloc(sizeof(linkstack));

p->datax; p->nexth->next;

h->next=p;

return h;

}


4390620

top

top

...

^

linkstack *POPLSTACK(slnodetype *top, datatype *datap)

{ slnodetype *p;

if (top->next==NULL)

{printf(under flow\n); return NULL;}

else

{ptop->next;

*datapp->data;

top->nextp->next;

free(p);

return top;

}

}


4390620

    • (front)

    • (rear)

    • (FIFO,First In First Out)


4390620

1

2

3

4

5


4390620

  • front == NULL


4390620

typedef struct

{ linklist *front,*rear;

} linkqueue;


4390620

SETNULL(linkqueue *q)

{ q->frontmalloc(sizeof(linklist));

q->front->nextNULL;

q->rearq->front;

}


4390620

int EMPTY(linkqueue *q)

{ if q->front==q->rear)

return(TRUE);

else

return(FALSE);

}


4390620

datatype FRONT(linkqueue *q)

{ if (EMPTY(q))

{printf(queue is empty\n);return NULL;}

else

return(q->front->next->data);

}


4390620

ENQUEUE(linkqueue *q,datatype x)

{ q->rear->nextmalloc(sizeof(linklist));

q->rearq->rear->next;

q->rear->datax;

q->rear->nextNULL;

}


4390620

datatype DEQUEUE(linkqueue *q)

{ linklist *s;

if (EMPTY(q))

{printf(queue is empty\n);return NULL;}

else

{ sq->front;

q->frontq->front->next;

free(s);

return(q->front->data);

}

}


4390620

s


4390620

#include <stdlib.h>

struct node {

char data;

struct node *next;

};

1 create_list(char *s) { /**/

struct node *head,*p,*q;

head=(struct node *) malloc(sizeof(struct node));

p=q=head;

while(*s!='\0')

{ p=(struct node *) malloc(sizeof(struct node)) ;

p->data= 2 ; /**/

q->next=p;

q= 3 ; /*q*/

s++;

}

p->next = NULL ;

return 4 ; /**/

}


4390620

void pr_in_reverse_order(struct node *p) /**/

{

if(p!=NULL)

{ pr_in_reverse_order(p->next); /**/

printf ("%2c", 5 ); /**/

}

}

void main()

{

char str[] = "link list";

struct node *head;

head = create_list(str);

pr_in_reverse_order(head->next);

}


  • Login