Skip to main content

Day 22: More with Timers | Dynamic Data Structures

Hardware: Using Timer Interrupts

Software: Dynamic Data Structures

Anything that stores data can be called as a data strucutre.
"Dynamic data structures are data structures that can grow and shrink during the execution of a program." 

Linked Lists

Linear data structure which consists of a group of nodes in a sequence which is divided in two parts. Each node consists of its own data and the address of the next node and forms a chain.

Advantages

  • Dynamic, allocates memory when required
  • insertion and deletion easily implemented
  • Stacks and queues easily executed
  • Reduces access time

Disadvantages

  • Memory wasted by pointers (require extra memory)
  • No element can be accessed randomly
  • reverse traversing difficult

Applications

  • Used to implement stacks, queues, graphs, etc. 
  • Allows you to insert elements at beginning and end of list
  • Don't need to know size in advance
Head is pointer that points to the first node in linked list. 
To access, use pointer head to reference info in first node, then, since first node contains pointer to next node, we can move to second node. Last node in list will contain pointer value of null to indicate end. 

Example 1.1
This example shows show each node in a linked list is represented

struct node
{
int data;
struct node *link;
};

To insert value into linked list, location for insertion must be found. Use pointer to first node to access first data value in the list, and if data value is less than value to be inserted, move to next data value using pointer in current node. 

Can be inserted in one of four places:
  • Before first node
  • Between two nodes
  • After last node
  • Into empty list
Similar process for deleting value from linked list. 

Comments

Popular posts from this blog

Day 25: Python, Graphing, 3D Visualization and Inertial Measurement

Python Arduino Code int trigPin=13; //Sensor Trig pin connected to Arduino pin 13 int echoPin=11; //Sensor Echo pin connected to Arduino pin 11 float pingTime; //time for ping to travel from sensor to target and return float targetDistance; //Distance to Target in inches float speedOfSound=776.5; //Speed of sound in miles per hour when temp is 77 degrees. void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(trigPin, LOW); //Set trigger pin low delayMicroseconds(2000); //Let signal settle digitalWrite(trigPin, HIGH); //Set trigPin high delayMicroseconds(15); //Delay in high state digitalWrite(trigPin, LOW); //ping has now been sent delayMicroseconds(10); //Delay in low state pingTime = pulseIn(echoPin, HIGH); //pingTime is presented in microceconds pingTime=pingTime/1000000; //convert pin...

Day 19: Project 2

Our project was a test stand for rocket motors Using an LCD screen, we could choose a display mode, and it would display the selected value. Unfortunately, we were unable to calibrate the pressure sensor, so all we ended up with was a load cell. We used the HX711 library for this. The LCD screen displayed the maximum force experienced during the test Code for MotorSensors.h #ifndef _MOTORSENSORS_ #define _MOTORSENSORS_ #include <LiquidCrystal.h> //Include Liquid Crystal Library #include <HX711.h> //Include HX711 Load Cell library #include "HX711.h" //Include Load Cell header file #include <math.h> //Include math library #define calibration_factor -8815 //set calibration factor #define DAT 3 //define DAT pin #define CLK 2 //define CLK pin #define pressurePin A1 #define tempPin A2 HX711 scale(DAT,CLK);  LiquidCrystal lcd(8,9,4,5,6,7); //Define LCD pins //Initialize variables float maxkg=0;  float currentval=0; float maxforce=0; char mo...