This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"fmt" | |
"strings" | |
_ "github.com/go-sql-driver/mysql" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef LINKED_H | |
#define LINKED_H | |
struct Node; | |
typedef struct Node Node; | |
struct Node | |
{ | |
int value; //value will hold the value of our node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void push_list(LinkedList* list, int value){ | |
Node* n; | |
n=(Node*)malloc(sizeof(Node)); //intializing new node | |
n->value=value; //setting value of new node | |
if(!list->tail){ | |
//It means we are pushing our first node, so intially header and tail node will be same |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int pop_list(LinkedList* list){ | |
if(!list->head) return -1; //It means, linked list is empty | |
int value; //holds value of node | |
value=list->head->value; //accessing node | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LinkedList* new_linked_list(){ | |
LinkedList* x; //Declaring a new instance of linked list | |
Node* n;//to do some temporary arrangements | |
x=(LinkedList*)malloc(sizeof(LinkedList)); // allocating memory for the linked list | |
return x; //returing it back | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int length_list(LinkedList* list){ | |
return list->length; //returning length of the linked list | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void delete_list(LinkedList* list){ | |
Node* i; | |
/** | |
* Deallocating memory associated with each node | |
* Starting from head node | |
* Ends whenever we reach at the end | |
* We go to next node in each iteration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef STACK_H | |
#define STACK_H | |
/** | |
* Defination of Basic Stack Structure | |
*/ | |
typedef struct | |
{ | |
//size of stack | |
int size; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef STACK_H | |
#define STACK_H | |
/** | |
* Defination of Basic Stack Structure | |
*/ | |
typedef struct | |
{ | |
//size of stack | |
int size; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stack.h" | |
#include<stdlib.h> | |
BasicStack* new_basic_stack(int cap){ | |
BasicStack* s; | |
//Allocating memory for Basic Stack Structure | |
s=(BasicStack*)malloc(sizeof(BasicStack)); | |
//Allocating memory for Array used to hold stack | |
s->ar=malloc(sizeof(int)*cap); |
OlderNewer