Está en la página 1de 20

VARIABLES DECLARADAS ANTES DE SU USO

#INCLUDE <stdio.h>
Main()
{
printf (hola mundo);
}
%d entero
%f real
%6,2f
Loops
While (expresin ){
Orden;
}
For (exp1;exp2;exp3){
Orden
}

#include <stdio.h>
Int power(int a,int base);
Main ()
{
Int x=power(int a;int b);
Printf (la wa %d , x);
Return 0
Sino retorno nada se return cero

}
Int x=10
Int power (int a , int base)
{
Int i;
Int P=1;
For (i=1;i<a;i=i+1)
P=p*base;

Return p;
}

ARREGLOS
Declaracin
Char

cosa[largo n]

Int

cosa[larguito]

Funcin len
Int len(char palabra[])
{
Int i;
i=0;
while (palabra[i]!=o/ )
i=i+1;
return i ;
}

Funcin conversin
Int con(char s[])
{
Int i ,n=0;
For (i=0;s[i]>0&&s[i]=<9,i=i+1)
N=n*10+(s[i]-0);
Return n;
}

S[i]-0 valor numrico

PUNTEROS
c=&p
*p

---- le asigna un direccin de memoria osea apunta


----> valor del coso

Void no retorna pnada


Void swap (int *px , int *py)
{
Int temp;
Temp=*px;
*py=*px;
*px=temp;
}
Int *P
Char a[]
*pa=a[0]

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

Int strlen(*p,a[])
{
Int n;
For(n=0;*s!=/0;s=s+1)
N=n+1;
Return n;
}

ESTRUC TURAS
Ej
Struct point{
Int x;
Int y ;
}
Struct rect{
Struct point pt1;
Struct point pt2;
}

Puntero a estrucutura ejemplo:


Struct point
{ int x;
Int y;
}
*p=point
*px
*py

Listas
Struct nodo

..

{
Int data;
Struct node*next;
}nodo

Lista3 {
Struct nodo *one=null;
Struct nodo *two=null;
Struct nodo *three=null;
One = malloc(sizeof(struct nodo));
Two=malloc(sizeof(struct nodo));
Three =malloc(sizeof(struct nodo);
Onedata=n1
One next=two
Two data=n2
Two next=three
Three data=n3
Three next=null
Return one
}

Int lenght(struct nodo*lista)

{
Int count=0;
Struct nodo *now=lista;
While (*now!=null)
{
now=nownext;
Count=count+1;
}
}

Int print(struct node *lista )


{
Main ()
{
Struct node *now=lista;
While (now!=null)
{
Printf (%d nowdata);
Now=nownext;
}}
Struct node *newnode{
Newnode=mallloc(sizeof(struct node))
Newnode data=coso

Newnodenext=one
ONE =newnode;
}

PUSH (STRUCT NODE **HEADREF,INT DATA)


{
NEWNODE DATA=DATA
Newnode next=head
*Headref=newnode
}

Int Pop(struct nodo**headreff){


Struct nodo head;
Int save ;
Head=*headref
Assert( head==null);
Result=headdata;
*head ref=headnext;

Free(head);
Return result
}

Lista doblemente enlazada

Typedef struct nodo {


Int dato;
Struct nodo *prev;
Struct nodo *next;
}

Push (nodo **head, int dato){


Nodo *newnode=malloc(sizeof(nodo));
Newnodedata =dato
Newnode*next=*head
Newnode *prev=null
*head=newnode
}

int Pop{nodo **headref){


Struct nodo temp=*headref;
int result
If (tempnext!=null)
*headref =tempnext
Result=tempdata
Free (temp)
*headrefprev=null}
Return (result)
Else{
*headref==null
Result=tempdata
Return (result)
Busca o hace el pop para una lista enlazada doble

Stack
Typedef struct stack{
Int dato;
Int tems[maxsize];
}stack;

Void push(stack *ps,int x){


If (pssize==stacksize){
Fputs(error :stacks overflow \n,stderr);
Abort();}
Else{
Psitems[pssize++]=X
}
}

Int pop (stack *ps)


{
If (pssctacks==0){
Fputs (error:stacks underflows , stderr);
Abort()
}else
Returns psitems[--pssize];
}

Stack con lista simplemente enlazada


Typedef struct stack{
Int data;
Struct moldestack *next;
}stack

Void push(stack **headref, int algo)


{ stack *nodo=malloc(sizeof(stack));
If (node==null){
Fputs (error:no space avaible for nodo, stderr);
Abort()
}else{
Node data=algo;
Nodenext=empty(*head)?null:*head;
*head=node
}}

Pop(stack **head){
Int result;
If (empty(head)){
Fputs(error : stacks is underflows,stderr);
Abort();
}else{
Stack *top =*head
Result= *headdato
*head=*topnext
Free (top)

}}

Arboles binarios de bsquedas


Typedef struct moldenodo{
Int dato;
Struct moldenodo *left;
Structmoldenodo *right;
}nodo;

Lookup(nodo *node , int target)


{
If (nodo==null);
Return (nodo!=null);
}else{
If ( target=nodo data){

Return(true);
}else{
If (target>nododata){
Return (lookup(nodeleft,target);
}else{ Return (lookup(noderight,target));
}}}

Typedef struct nodo{


Int clave;
Struct nodo *left;
Struct nodo *right;
}nodo;

Nodo *creanodo(int dato)


{ nodo *pn=malloc(sizeof(nodo))
If (pn==null)
{Exit(1)}else{
pn clave=dato;
pn right=null;
pn left=null;
}
Return (*pn);

Void recorraenorden(nodo *pn)


{
If (pn==null)
Recorraenorden(nodo *left);
Printf (%d \n , pn clave);
Recorraenorden (nodo *right);
}

Void inorder(nodo *p ,int nivel)


{
If (p!=null)
{inorder(nodo *left , int nivel++);
Printf ( %d %d \n , pclave ,nivel);
Inorder (nodo *right,int nivel++);
}

Nodo buscariterativo(int clave,nodo *p)

{While( p!=null)
{
If (pnkey==clave) {return pn;}
Else{if (pnkey>clave;){pnright;
}else{pnleft;}return pn}}

Nodo buscarecursiva(nodo *pn ,int valor)


If pnkey==null
Return false
Else{
{ if (pnkey==valor) {return pn;
}else{ if (pnkey>valor){return(buscarecursiva(nodo pnright, int
valor);
}else{return(buscarecursiva(nodo pnleft,int valor)}}}}

Int buscarminimo(nodo *pa){


If (pa==nul return (null))
If (paleft!=null){
Buscarminimo(paleft);

Return pa;}

Nodo insertarnodo(nodo *pn,int valor){


If (pn==null)
Return crearnodo(data);
}else{if (pnkey==valor)
{return (pn)}else{if (pakey<valor)
{return (insertarnodo(paleft,valor)}
Else{return(insertanodoleft)}
}}

Nodo Buscarmenosdesendiente(*pn)
{
If (pn==null ||pnright==null)
{return (null)}
Else {
Return(buscarminimo(nodo pnright)}}

Nodo *descartar(nodo *pa,int valor)


{
Nodo *temp
If( pn==null){
Printf (no existe);}
Else{ if (pnkey<valor)
{pnleft=descartar(pnleft,valor);}
if (pnkey>valor){
pnright=descartar(pnright,valor);}
else{
if (pnright && pnleft){
temp=desendienteminimo(pnright,valor)
pnkey=tempkey
pnright =descartar(pnright,tempkey)}
else{
temp=pn;
if (pnright==null){
pn=pnleft;
if (pnright==null)
{pn=pnleft;}
Free(temp)
}}return (pn);}

Nodo *borrra(nodo *pn){


If (*pn==null){
Pnright=borra(pnright);
Pnleft=borra(pnleft);
Free(pn);}}

Tarea
Altura numero de hojas nodos unir dos arboles

Void listareversa(**a){
M=len(*p)
Struct nodo temp=*a
Struct node *newlist=null
While(m!=0){
Int i ;
For (i=1,i<=m,i++)
{temp=tempnext;}
Newnode(*newlist,tempdata)

m
}
Void newnode(*lista,int dato)
{ temp=malloc(sizeof(structnodo))
Struct nod temp1=lista
If (lista==null)
Tempdata=dato
Tempnext=null
Lista=temp
}else{
While(temp1next!=null){
Temp1=temp1next
}temp1next=temp
Tempdata=dato
Tempnext=null
}}

También podría gustarte