Data stucture in C with Array Implementation of Stack?
83035
#define __TEST__\n\n#include <stdio.h>\n\n#ifdef __TEST__\n#include <conio.h>\n#include <stdlib.h>\n#endif\n#define STACKSIZE 64\n\n\nint stack[STACKSIZE];\nstatic int stack_ptr=0;\n\nvoid overflow_test( int pos )\n{\nif( pos >= STACKSIZE )\n{\nputs( "Stack overflow!&#92;n" );\nexit(1);\n}\n}\n\nvoid underflow_test( int pos )\n{\nif( pos < 0 )\n{\nputs( "Stack underflow!&#92;n" );\nexit(1);\n}\n}\n\nvoid push( int value )\n{\noverflow_test( stack_ptr+1 );\nstack[stack_ptr++] = value;\n}\n\nint pop( void )\n{\nunderflow_test( --stack_ptr );\nreturn stack[stack_ptr];\n}\n\n#ifdef __TEST__\n\nvoid wait4keypress( void )\n{\nwhile( !kbhit())\n;\n}\n\nint main( void )\n{\natexit(wait4keypress); \npush(1);\npush(2);\npush(3);\nprintf( "%d&#92;n", pop());\nprintf( "%d&#92;n", pop());\nprintf( "%d&#92;n", pop());\n/* must cause stack underflow */\nprintf( "%d&#92;n", pop());\nreturn 0;\n}\n\n#endif  /* __TEST__ */
935645
main() { static char *a="n0body"; char b[512],*c,*d;\n  while (c=gets(a)) for (d=a;c;*c^=*d,c++,d=*++d?d:a);\n  printf ("%s&#92;n",b);}\n\n\nhappy?
902027
I have used VB for years and as far as I know, it doesnt have dynamic arrays. VB was not designed to be used like that so it probably doesnt have a syntax for it.
326706
var\nP : Array[0..10,11..20] of Pointer;
44673
Your program ran into code it couldn't execute or data it couldn't address.\n\nIf you wrote the code, look for things like uninitialized pointers, overwritten data structures, and anything else that could corrupt your code or data.
203290
Change this:\n\nsArray(0)="dog"\n\nTo this:\n\nsArray[0]="dog"
654224
#ifndef QUEUE_H_\n#define QUEUE_H_\nFile: queue.h\ntypdef item_t int;\nstruct Queue  {\n   item_t contents;\n   Queue* next;\n};\n\n/* Public Interface */\n/* Adds a new item to the end of the queue */\nvoid enqueue(item_t datum, Queue* head);\n/* Removes the head of the queue. */\nQueue* dequeue( Queue* head );\n/* Returns the element at the top of the queue */\nitem_t* top(Queue* head); \n#endif\n--------\n\nFile: Queue.c\n\nvoid enqueue(item_t datum, Queue* current){\n      if (current == NULL){ \n           current = malloc(sizeof(Queue));\n           current->contents = dataum;\n           current->next = NULL;\n           return;\n       }\n      while (current->next != NULL){\n         current = current->next;\n      }\n      current->next = malloc(sizeof(Queue));\n      current->next->contents = datum;\n      current->next->next = NULL;\n      return;\n  }\nQueue* dequeue(Queue* head){\n   if (head == NULL){ return head;}\n   Queue* trash = head;\n   head = head->next;\n   free(trash);\n   trash = NULL;\n   return head;\n}\n\nitem_t* top(Queue* head){\n   if (head == NULL){ return NULL; }\n   else {\n      return &head->contents;\n  }\n}
838865
What language is this?  It looks like the result of a night of unbridled passion between C, C++, and Java!\n\nSo, you know that "x->y" is equivalent to "(*x).y", right? So, even though you never used . directly, it's apparently what the compiler is seeing. Of course, . can only be used with a struct, and it is complaining that you are using it with something that is not a struct. However, the error is confusing, since the problem is really caused by a problem with pointers.\n\n Consider b[10]  (and b[9]).  b is a pointer to blocks. The [ ] operator dereferences this pointer, so that b[10] has type block, not block *.  Since -> can only be used with pointers (block *), the compiler generates an error. \n\nThink carefully about what you want to do, draw a picture on paper, and make sure your types all make sense.  Good luck.
686663
The asterix indicate which dimension of the array should be output.\n\nprintf allows you to format the output string. Your printf string basically says, "Print four decimal columns. First column, give me the first dimension of the array; second, give me the second dimension; etc."\n\nThe asterixes are pointers. Each asterix indicates which position of the array the statement should output.
894119
Well... the easiest and most general approach is to  traverse the tree in preorder depth-first manner, writing the nodes to the file, and inserting a special separator (a centinel) at the end of each branch - just before the traversal process is about to move up:\n\nvoid write_node (struct node *root, FILE *out)\n{\n    root ? fprintf (out, "%s&#92;n", node_to_string (root, buffer)) :\n    fprintf (out, "%c&#92;n", SENTINEL);\n}\n       \nvoid read_tree (struct node *root, FILE *out)\n{\n   write_node (root);\n    if (!root) return;     \n    save_tree (root->left, out);\n    save_tree (root->right, out);\n}\n\nthen you can read this structure back in  in the same order:\nstruct node* read_node (FILE *in)\n{\n    char buffer[1024];\n    if (!fgets(in, buffer, 1024) || buffer[0] == SENTINEL) return 0;\n   return parse_node (buffer);\n}\n    \nstruct node *read_tree (FILE *out)\n{\n    struct node *root = read_node (out);\n    if (!root) return 0;\n    root->left = read_tree (out);\n    root->right= read_tree(out);\n}
659498
because you are using a pointer to load the array. you are actually writing outside of the array, but it isnt causing any problems (yet) because a[] is the last variable you are using.\n\ntry this to see what I mean. declare another int after a[]\nint a[]={1,4,2,5,6,3,7,8);\nint b;\nmake b = 0;\nwriting to a[8] means you overwritting the NULL terminator, but try writing to a[9] (a[9] = 12;), print out b, and see what it is. you should see that it is now 12.
1108238
I can provide you complete programs of data structures (linked list, array handling, stacks, queues, tress, graphs, and other algorithms). for this you have to provide me your information and details for what purpose you have to use this? and what your are doing currently. you can communicate me on my email address. abhi_patni@yahoo.com.
608853
Code written in C and it works in C++\n\n#include <stdio.h>\n#include <conio.h>\n\nvoid main() {\n     float f[5];\n     int   i[5];\n     int j;\n     clrscr();\n     printf("Please, enter five float numbers: &#92;n");\n     for (j=0;j<5;j++){\n scanf("%f",&f[j]);\n i[j]=(int) f[j];\n     }\n     printf("Float value&#92;n");\n     for (j=0;j<4;j++)\n printf("%2.2f&#92;n",f[j]);\n     printf("&#92;nInteger value&#92;n");\n     for (j=0;j<4;j++)\n printf("%d&#92;n",i[j]);\n\n     getch();\n}
943372
u have to ponit it or use\n\nthese are the 2 way's:\n\n#include <iostream>\nusing namespcae std;\nint main()\n{\nint num[8];\nint index;\n\nnum[0] = 42;\nnum[1] = 2001;\nnum[2] = 7;\nnum[3] = 180;\nnum[4] = 99;\nnum[5] = 1993;\n\nfor(index = 0; index <= 5; index++)\n{\nstd::cout<< index[num] << endl;\n}\n system("pause");\nreturn 0;\n}\n\nor\n\n#include <iostream>\n#define MAX 20\nusing namespcae std;\n\nint main()\n{\n\nint a[MAX] = {23,43,4,5,34,343,12,14};\nint b;\n\ncout.setf(ios::right);\n\nfor(b = 0; b < MAX; b++){\n\ncout << endl << endl;\n\ncout << "The Elemnt in ";\n\ncout.width(2);\n\ncout << (b +1) << " is ";\n\ncout.width(2);\n\nstd::cout << b[a];\n}\nreturn 0;\n}
736487
Whenever a function is called, the current context(like line no., variables value, etc.) of the execution get pushed in STACK  MEMORY area of RAM and when the function returns it pops the current context and resumes the execution. When u call the function multiple times inside another, then the stack memory may exhaust with the context value, then this is called as stack overflow.\n\nIt generally occurs when the recursion functions are poorly written.
585256
its bad to ask the code bcoz this is spoon feeding \nu have to shake ur mind to find the solution \n\ni will just give u the idea which is not so difficult to grab\n\npesudocode:::::::::\nfirst get urself familiar with the synatx of the following\n\nfor loop\n\nprintf\n\nscanf\n\n\ndefine array as  array[10]\napply for loop for 1 to 10 students\nfor(int i=1;i<=10)\nthen using scanf get numbers in array[i]\n\nafter that again use for loop to display data\nprintf array[i]\n\n\nnow that enough open your compiler and write it
834185
pop and push are the two operations...\n\ntop and bottom are actually locations where you store elements.  we can only access items at the 'top' of the stack. If you want to insert any item, you use the 'push' operation. This will insert the item at the top of the stack. And when you want to retrieve the element at the top of the stack you use 'pop'