Exercicios sobre a matéria da P3 de 2006.1 Listas, Árvores e Tabela de Dispersão.

Slides:



Advertisements
Similar presentations
The Derivative in Graphing and Application
Advertisements

Incomplete Structs struct B; struct A { struct B * partner; // other declarations… }; struct B { struct A * partner; // other declarations… };
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
EENG212 Algorithms and Data Structures
CSCE 3110 Data Structures & Algorithm Analysis
Chapter 4 Lists Pointers Singly Linked Lists
CSEB324 Data Structures & Algorithms
Data Structures Linked Lists Linked List Basics. Array Disadvantages Arrays, although easy to understand have lots of disadvantages Contiguous Memory.
Double Linked List Operations Dr. David Tsai 2010/4/12.
418115: II. Linked List A linked list can be thought of a chain of linked list elements. A linked list element contains a single data item, and contains.
CSCE 3110 Data Structures & Algorithm Analysis
LIST PROCESSING.
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
C’ POINTERS Basic&Examples. Q:what’s the output? int array[] = { 45, 67, 89 }; int *array_ptr = array; printf(" first element: %i\n", *(array_ptr++));
SEE C GO Provisional Title. Syntax Types int, float, double, char, void Identifiers foo Operators + - * / ^ Delimiters ; {} () “” ‘’ Keywords return,
Recursion Prog #include <stdio.h> #include<conio.h> main()
Data Structure Lecture-5
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Doubly-linked list library.
Chapter 6 Structures By C. Shing ITEC Dept Radford University.
Data Structures: Doubly Linked List1 Doubly linked list l The linear linked list is accessed from the first node each time we want to insert or delete.
C Structures Basics of structures Typedef. Data Hierarchy Byte –8 bits (ASCII character ‘A’ = ) Field –Group of characters (character string “Fred”)
Programming Languages and Paradigms The C Programming Language.
LCS Non-Dynamic Version int function lcs (x, y, i, j) begin if (i = 0) or (j = 0) return 0; else if (x[i] = y[j]) return lcs(x, y, i-1, j-1)+1; else return.
Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.
Divisor máximo de dois inteiros. unsigned int gcd(unsigned int A, unsigned int B) { if (B > A) return gcd(B,A); else if (B==0) return A; else return gcd(B,A%B);}
Lecture 09 Strings, IDEs. METU Dept. of Computer Eng. Summer 2002 Ceng230 - Section 01 Introduction To C Programming by Ahmet Sacan Mon July 29, 2002.
Character String Manipulation. Overview Character string functions sscanf() function sprintf() function.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
ECE Application Programming Instructor: Dr. Michael Geiger Spring 2012 Lecture 31: PE5.
指標 Pointers.
C Intro.
Senem Kumova Metin Spring2009 BINARY TREES && TREE TRAVERSALS Chapter 10 in A Book on C.
Data Structures (Second Part) Lecture 3 : Array, Linked List, Stack & Queue Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering.
Computer Programming Link List (Insertion, Printing and Deletion functions) Lecture 23.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 7 : September 8.
Memory allocation CSE 2451 Matt Boggus. sizeof The sizeof unary operator will return the number of bytes reserved for a variable or data type. Determine:
Create your own types: typedef #define N 3 typedef double scalar; /* note defs outside fns */ typedef scalar vector[N]; typedef scalar matrix[N][N]; /*
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
Introduction to Data Structures Systems Programming.
Passing Structure to function.  structure to function structure to function  Passing structure to function in C Passing structure to function in C 
EXERCISE Arrays, structs and file processing. Question You own a pet store. You want to keep an inventory of all the pets that you have. Pets available.
Computer Programming for Engineering Applications ECE 175 Intro to Programming.
ENEE150 – 0102 ANDREW GOFFIN Dynamic Memory. Dynamic vs Static Allocation Dynamic  On the heap  Amount of memory chosen at runtime  Can change allocated.
Sudeshna Sarkar, CSE, IIT Kharagpur1 Structure and list processing Lecture
Stacks This presentation shows – how to implement the stack – how it can be used in real applications.
 Learn how to form strings using one-dimensional array  String manipulation functions:  strcpy  strrev  strcmp  Program using strings.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
C Lab 2 Intermediate Pointers & Basic Structures.
1 C Basics. 2 The C Language Spirit Made by professional programmers for professional programmers Very flexible, very efficient, very liberal Does not.
Dynamic Allocation Review Structure and list processing
“Studying C programming excluding pointers is meaningless.” d0m3z
Introduction to Programming
Programming Languages and Paradigms
Programming Paradigms
CSCI206 - Computer Organization & Programming
Programming Languages and Paradigms
Programmazione I a.a. 2017/2018.
Recursion.
Linked Lists Chris Wright Winter 2006.
Engr 0012 (04-1) LecNotes
Example passing the address of x x pint or
Review & Lab assignments
Variables in C Declaring , Naming, and Using Variables.
Programming Language C Language.
C Programming Lecture-8 Pointers and Memory Management
CSCE 206 Lab Structured Programming in C
Presentation transcript:

Exercicios sobre a matéria da P3 de Listas, Árvores e Tabela de Dispersão

ex_p3.c

int intervalo(Arv* a, int x1, int x2) { if (a==NULL) return 0; if (a->info>x2) { return intervalo(a->esq,x1,x2); } else if (a->info dir,x1,x2); } else { /* pertence ao intervalo */ return 1 + intervalo(a->esq,x1,x2) + intervalo(a->dir,x1,x2); }

hashAluno.c

int busca(Hash tab, char* nome) { int i = hash(nome); Aluno* p; for (p=tab[i];p!=NULL;p=p->prox) { if (strcmp(p->nome,nome)==0) return p->quant; } return -1; } int hash(char* nome) { int i,soma=0; for (i=0;nome[i]!=\0;i++) soma=(soma+nome[i])%N; return soma; }

lista2.c

struct lista { char nome[81]; float nota; struct lista* prox }; typedef struct lista Lista; Lista* insere (Lista* lst, char* nome, float nota) { Lista* novo=(Lista*) malloc(sizeof(Lista)); strcpy(novo->nome,nome); novo->nota=nota; novo->prox=lst; return novo; }

Lista* retira_ultimo(Lista* lst) { if (lst==NULL) return NULL; else{ Lista* ant=NULL; Lista* p=lst; while (p->prox!=NULL) { ant=p; p=p->prox; } free(p); if (ant!=NULL) { ant->prox=NULL; return lst; } else return NULL; }

int cheia(Arv* a) { if (a==NULL) return 1; if (a->esq==NULL&&a->dir==NULL) return 1; if (a->esq==NULL||a->dir==NULL) return 0; return cheia(a->esq)&&cheia(a->dir); }

int maximo(ArvGen* a) { if (a->prim==NULL) return a->info; else { int max=a->info; ArvGen* p; for (p=a->prim;p!=NULL;p=p->prox) { int mp=maximo(p); max=(max>mp)?max:mp; } return max; }

Lista* constroi(int n, int* v) { int i; Lista* head=NULL; for (i=0;i<n;i++) { Lista* novo=(Lista*) malloc(sizeof(Lista)); novo->info=v[i]; novo->prox=head; head=novo; } return head; }

int soma_info_folhas (Arv* a) { if (a==NULL ) return 0; else if (a->esq==NULL&&a->dir==NULL) return a->info; else return soma_info_folhas(a->esq)+soma_info_folhas(a->dir); }

int num_nos_x(ArvGen* a,int x) { if (a->prim==NULL) return (a->info>x)?1:0; else { ArvGen* p; int n=(a->info>x)?1:0; for (p=a->prim; p!=NULL; p=p->prox) { n+=num_nos_x(p,x); } return n; }

void imprime (Arv* a) { if (!arv_vazia(a)){ imprime(a->esq); /* mostra sae */ printf("%d ", a->info); /* mostra raiz */ imprime(a->dir); /* mostra sad */ }

/* conta o numero de nos ate o nivel n */ int conta (Arv* a, int n) { if (a==NULL || n==-1) return 0; else return 1+conta(a->esq,n-1)+conta(a->dir,n-1); }

void imprime (ArvGen* a) { ArvGen* p; printf(" info); for (p=a->prim; p!=NULL; p=p->prox) imprime(p); /* imprime cada sub-árvore filha */ printf(">"); }