Skip to main content

Posts

Showing posts with the label C++

Basic Priority queue in C

The source code of basic priority queue is given : #include<stdio.h> #include<malloc.h> void insert(); void del(); void display(); struct node     {         int priority;         int info;         struct node *next;     }*start, *q, *temp, *new; typedef struct node *N; int main() {     int ch;     do      {             printf( "\n[1] INSERTION\t[2] DELETION\t[3] DISPLAY [4] EXIT\t:" );             scanf( "%d", &ch );             switch ( ch )                 {               ...

SCTP server client Code in C

Client.c #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <netinet/sctp.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <errno.h> #define RECVBUFSIZE     4096 #define PPID            1234 int main() {        int SctpScocket, in, flags;        socklen_t opt_len;        char * szAddress;        int iPort;        char * szMsg;        int iMsgSize;        char a[1024];            struct sockaddr_in servaddr = {0};        struct sctp_status status = {0};    ...

UDP server client in c

Server #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <stdlib.h> int main() {         int sock;         int addr_len, bytes_read;         char recv_data[1024],send_data[1024];         struct sockaddr_in server_addr , client_addr;         if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {             perror("Socket");             exit(1);         }         server_addr.sin_family = AF_INET;         server_addr.sin...

TCP server client in C

Client Code #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <netdb.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> int main() {         int sock, bytes_recieved;         char send_data[1024],recv_data[1024];         struct hostent *host;         struct sockaddr_in server_addr;         host = gethostbyname("127.0.0.1");         sock = socket(AF_INET, SOCK_STREAM,0);         server_addr.sin_family = AF_INET;         server_addr.sin_port = htons(5000);         server_addr.sin_addr = *((struct in_addr *)host->h_addr);   ...

Shift Reduce algorithm source code in c for Compiler

#include #include #include #include #include using namespace std; struct stru1 { char non_ter[1],pro[25]; }cfg[25]; int n,st=-1,j,i,t=-1,m; int v,c,p=1; char str[20],stack[20],ch,tmp[10]; void match(int k); void matchl(int k); int main() { printf("Enter the number of productions:\n"); scanf("%d",&n); printf("\n"); printf("Enter the productions on LEFT and RIGHT sides:\n"); for(i=0;i \n"); scanf("%s",cfg[i].pro); printf("\n"); } printf("Enter the input string:\n"); scanf("%s",str); printf("\n"); i=0; do { ch=str[i]; stack[++st]=ch; tmp[0]=ch; match(1); i++; }while(str[i]!='\0'); c=st; v=st; puts(stack); printf("\n"); while(st) { --st; v=st; t=-1; p=0; while(v<=c) { ...

Iterative Deeping algorithm source code in C++

 Source code of iterative deeping search is given. # include <stdio.h> # include <iostream> # include <sstream> # include <algorithm> # include <string.h> # include <string> # include <math.h> # include <queue> # include <vector> using namespace std; int node,edge; vector<int>adj[100]; bool flag[100]; int dist[100],par[100],leb[100]; int bfs(int s,int e,int lev) {    int i,cur,head,tail,que[10000],l=0;    head = tail = 0;    que[head++] = s;    flag[s] = 1;    dist[s] = 0;    par[s] = -1;    leb[s] = 0;    memset(leb,0,sizeof(leb));    while(head != tail)    {        cur = que[tail++];        if(leb[cur] == lev)        {            return 0 ;      ...

Object Transformation source code in c++ with Glut/opengl

In this algorithm one rectangle has been transformed 30-degree angle and it also move from the current object by x 100 and y 100. Here the white rectangle is input and red one is output.         INPUT:             OUTPUT:       #include <windows.h> #include <GL/glut.h> #include <stdlib.h> #include <iostream> #include <string> #include <string> #include <ctype.h> #include <math.h> #include <stdio.h> #include <map> #include <vector> using namespace std; int trans_x,trans_y; #define pi 2.0*acos(0) long x_min,x_max,y_min,y_max; vector <int>x_cor; vector <int>y_cor; long draw_line(long x_start , long y_start , long x_end, long y_end) {     glBegin(GL_LINES);     glVertex2f(x_start,y_start); //start points     glVertex2f(x_end,y_end); // end...