Data Structure

Tuesday, December 23, 2008 | Labels: | 0 comments |

Data Structure

Definition : In computer science, a data structure is a way of storing data in a computer so that it can be used efficiently.

View definition from wikipedia.org

Chapter 1 : Revision on Array and Structure, String, Recursion, Pointers, Dynamic Memory Allocation

Assignment #1, Sample Answer for Assignment 1, Q2

String manipulation : Assignment on String

Pointer

  • Notes
  • Code samples

Memmory Allocation :

  • Notes: refer to pg 487; A Structured Programming Approach using C, by Forouzan and Gilberg.
  • Wikipedia : Dynamic Memory Allocation
  • Wikipedia : malloc()
  • Sample code
  • Exercise 1 :
  • Write a program that will receive a set of characters from the user. The number of the characters is not known, but it is decided by the user. Printf the characters in reverse. Use malloc to dynamically set the memory space for the characters.
  • Exercise 2 :
  • Write a program that will receive a set of integers from the user. How many integers to enter is decided by the user. Find the sum of the integers, average, the smallest and the highest. Sort the integers in ascending order. Use malloc to dynamically set the memory space for the integers.
Chapter 2 : Linked List

Notes

Sample codes

Exercises

1. Develop a linked list of integers where the number of integers are unknown (depends on the users input). Receive all the numbers entered by user and put each integers in a node. Create the linked list of the nodes. After that traverse all the nodes and accumulate the sum of all the integers.

2. Develop a linked list of students information. The information of the students are matrix number and name.Use the follwing data structure to create the node. After the list is created, traverse the node and display the content.

typedef struct node{

char matrix[10];

char name[20];

struct node *next;

}NODE;

3. Develop a linked list of numbers. The data of numbers are collected are from an input file. Provide the menu for the user to insert new data and insert the new data node at the back of the list. Provide also the menu to find data, find node and display data, delete node and delete node with a data provided by user.

Chapter 3 :  

Final Exam Samples : soon...


Code samples :

  1. Animal Tree
  2. Compression using Huffman encoding and Greedy Algorithm.
  3. DeCompression of Huffman code.

Related Links :

  1. Simulation on Sorting 1 (you need JRE plugins installed to play the simulation applet)
  2. Simulation on Sorting 2 - by Ang Wai (you need JRE plugins installed to play the simulation applet)
  3. Simulation on Sorting 3- by Alejo Hausner (you need JRE plugins installed to play the simulation applet)
  4. Simulation on Huffman Code (you need JRE plugins installed to play the simulation applet)

Soon :

Sample code (home made) on : Animal tree game, simple compression and decompression using Huffman Code.