Example #1
0
//
// Routines
//
int
convert_dpme(DPME *data, int to_cpu_form)
{
#if BYTE_ORDER == LITTLE_ENDIAN
    // Since we will toss the block if the signature doesn't match
    // we don't need to check the signature down here.
    reverse2((u8 *)&data->dpme_signature);
    reverse2((u8 *)&data->dpme_reserved_1);
    reverse4((u8 *)&data->dpme_map_entries);
    reverse4((u8 *)&data->dpme_pblock_start);
    reverse4((u8 *)&data->dpme_pblocks);
    reverse4((u8 *)&data->dpme_lblock_start);
    reverse4((u8 *)&data->dpme_lblocks);
    reverse4((u8 *)&data->dpme_flags);
    reverse4((u8 *)&data->dpme_boot_block);
    reverse4((u8 *)&data->dpme_boot_bytes);
    reverse4((u8 *)&data->dpme_load_addr);
    reverse4((u8 *)&data->dpme_load_addr_2);
    reverse4((u8 *)&data->dpme_goto_addr);
    reverse4((u8 *)&data->dpme_goto_addr_2);
    reverse4((u8 *)&data->dpme_checksum);
    convert_bzb((BZB *)data->dpme_bzb, to_cpu_form);
#endif
    return 0;
}
Example #2
0
int main(){
    int x1= 3, x2=-123; 
    long x3=12345678912;
    printf("x1 = %d, reverse=%d\n", x1, reverse2(x1));
    printf("x2 = %d, reverse=%d\n", x2, reverse2(x2));
    printf("x3 = %ld, reverse=%d\n", x3, reverse2(x3));
    return 0;
}
Example #3
0
int
convert_block0(Block0 *data, int to_cpu_form)
{
#if BYTE_ORDER == LITTLE_ENDIAN
    DDMap *m;
    u16 count;
    int i;

    // Since this data is optional we do not want to convert willy-nilly.
    // We use the flag to determine whether to check for the signature
    // before or after we flip the bytes and to determine which form of
    // the count to use.
    if (to_cpu_form) {
	reverse2((u8 *)&data->sbSig);
	if (data->sbSig != BLOCK0_SIGNATURE) {
	    reverse2((u8 *)&data->sbSig);
	    if (data->sbSig != BLOCK0_SIGNATURE) {
		return 0;
	    }
	}
    } else {
	if (data->sbSig != BLOCK0_SIGNATURE) {
	    return 0;
	}
	reverse2((u8 *)&data->sbSig);
    }
    reverse2((u8 *)&data->sbBlkSize);
    reverse4((u8 *)&data->sbBlkCount);
    reverse2((u8 *)&data->sbDevType);
    reverse2((u8 *)&data->sbDevId);
    reverse4((u8 *)&data->sbData);
    if (to_cpu_form) {
	reverse2((u8 *)&data->sbDrvrCount);
	count = data->sbDrvrCount;
    } else {
	count = data->sbDrvrCount;
	reverse2((u8 *)&data->sbDrvrCount);
    }

    if (count > 0) {
	m = (DDMap *) data->sbMap;
	for (i = 0; i < count; i++) {
	    reverse4((u8 *)&m[i].ddBlock);
	    reverse2((u8 *)&m[i].ddSize);
	    reverse2((u8 *)&m[i].ddType);
	}
    }
#endif
    return 0;
}
Example #4
0
bool isPalindrome(struct ListNode* head) {
	if (head == NULL || head->next == NULL)
		return true;
	struct ListNode* p = NULL, *q = NULL;
	int totalLen = split2Half(head, &p, &q);
	reverse2(&q);
	bool isPalin = compare(p, q);
	reverse2(&q);
	while (p->next != NULL) {
		p = p->next;
	}
	p->next = q;
	return isPalin;
}
Example #5
0
int main()
{
	node* list1 = NULL;
	node* list2 = NULL;
	int c = 0;
	while(c++ < 10){
		add(&list1, c*c+1);
		add(&list2, c*12+1);
	}
	display(&list1);
	printf("max:%d  length:%d  sum:%d\n",max(list1),length(list1),sum(list1));
	display(&list2);
	printf("max:%d  length:%d  sum:%d\n",max(list2),length(list2),sum(list2));

	node* list3 = merge(&list1, &list2);
	display(&list3);

	node* list4 =reverse(&list3);
	display(&list4);

	node* list5 = reverse2(&list4);
	display(&list5);

	release(&list5);

	return 0;
}
Example #6
0
File: e8-5.cpp Project: hizcode/ppp
int main()
try
{
	vector<int> val;

	cout << "Please enter a sequence of integers ending with any non-digit character: ";
	int i;
	while (cin>>i) val.push_back(i);
	print("\nInput:\n",val);
	reverse1(val);
	print("\nReversed once:\n",val);
	reverse2(val);
	print("\nReversed again:\n",val);


	keep_window_open("~");	// For some Windows(tm) setups
}
catch (runtime_error e) {	// this code is to produce error messages; it will be described in Chapter 5
	cout << e.what() << '\n';
	keep_window_open("~");	// For some Windows(tm) setups
}
catch (...) {	// this code is to produce error messages; it will be described in Chapter 5
	cout << "exiting\n";
	keep_window_open("~");	// For some Windows(tm) setups
}
int main(){
	int arr[] = {10,20,30,40,50,60,70};
	linked_list * head = construct(arr, 7);
	display(head);
	linked_list * reversed = reverse2(head);
	display(reversed);
}
Example #8
0
int
convert_bzb(BZB *data, int to_cpu_form)
{
    // Since the data here varies according to the type of partition we
    // do not want to convert willy-nilly. We use the flag to determine
    // whether to check for the signature before or after we flip the bytes.
    if (to_cpu_form) {
	reverse4((u8 *)&data->bzb_magic);
	if (data->bzb_magic != BZBMAGIC) {
	    reverse4((u8 *)&data->bzb_magic);
	    if (data->bzb_magic != BZBMAGIC) {
		return 0;
	    }
	}
    } else {
	if (data->bzb_magic != BZBMAGIC) {
	    return 0;
	}
	reverse4((u8 *)&data->bzb_magic);
    }
    reverse2((u8 *)&data->bzb_inode);
    reverse4((u8 *)&data->bzb_flags);
    reverse4((u8 *)&data->bzb_tmade);
    reverse4((u8 *)&data->bzb_tmount);
    reverse4((u8 *)&data->bzb_tumount);
    return 0;
}
Example #9
0
int main(){

    //reverse1();
    reverse2();

    return 0;
}
Example #10
0
 void reverse(vector<string> &res,string s,int n,int step) {
     if (step < ((1 <<n) -1)) {
         s[n - 1] = 1 - (s[n - 1] - '0') + '0';
         res.push_back(s);
         reverse2(res,s,n,step+1);
     }
 }
Example #11
0
	int
main(int argc, char *argv[])
{
	int i;

	struct node *h = NULL;
	for(i = 0; i < 10; i++)
		h = insert_last(h, i);

	print(h);

	h = reverse(h, NULL);
	print(h);

	h = reverse2(h);
	print(h);

	h = delete_first(h);
	print(h);

	h = delete_last(h);
	print(h);

	h = insert_first(h, 11);
	print(h);

	h = insert_last(h, 13);
	print(h);

	h = insert_after(h, newnode(14), 13);
	print(h);

	return 0;
}
int main()
{
  char str1[] = "ala ma kota a kot ma ale ala go kocha a kot ja wcale";
  char str2[] = "1234567890";
  char str3[] = "";
  char str4[] = "a";
  reverse(str1);
  reverse(str2);
  reverse(str3);
  reverse(str4);
  printf("%s\n%s\n%s\n%s\n", str1, str2, str3, str4);
  reverse2(str1);
  reverse2(str2);
  reverse2(str3);
  reverse2(str4);
  printf("%s\n%s\n%s\n%s\n", str1, str2, str3, str4);
}
Example #13
0
// Reverse the ordering of words in a string 
void reverse_words(char* s) {

	reverse2(s, s + strlen(s) - 1); 

	char *begin = s; 
	char *temp = s; 

	while (*temp) {
		temp++; 
		if (*temp == '\0') {
			reverse2(begin, temp-1); 
		}
		else if (*temp == ' ') {
			reverse2(begin, temp-1); 
			begin = temp+1; 
		}
	}
}
Example #14
0
File: lc.c Project: Henry/Leda
static struct list* reverse2(struct list* todo, struct list* done)
{
    if (todo)
    {
        return reverse2(todo->next, newList(todo->value, done));
    }

    return done;
}
Example #15
0
int butlast(int lis){
	int res;
    
    res = NIL;
    while(!nullp(cdr(lis))){
    	res = cons(car(lis),res);
        lis = cdr(lis);
    }
    return(reverse2(res));
}
Example #16
0
int main(void){
	int a[] = {2, 4, 5, 5, 8, 9};
	Node *root = NULL;

	cp_array_link(&root, a, ARRAY_LEN(a));
	print_link(root);

	reverse2(&root);
	print_link(root);

	return 0;
}
int main(int argc, char *argv[])
{
    char str1[] = "hahaya"; //char *p = "hahaya"字符串常量 不可修改
    reverse1(str1);
    std::cout << str1 << std::endl;

    char str2[] = "hahaya";
    reverse2(str2);
    std::cout << str2 << std::endl;

    return 0;
}
Example #18
0
node * reverse2(node** list)
{
	node* p =*list;
	if(!p ||!(p->next)){
		return p;
	}
	node* tmp = p->next;
	node* head = reverse2(&(p->next));
	tmp->next = p;
	p->next =NULL;
	return head;
}
Example #19
0
File: 1.c Project: wy91092/svn
int main()
{
  int a[8]={1,2,3,4,5,6,7,8};
  pLink L1,L2;
  init_link(&L1);
  init_link(&L2);
  creat_link(a,L1,8);
  
  print_link(L1);
 // reverse_link(L1,L2);
  L1=reverse2(L1);
  print_link(L1);
  return 0;	
}
Example #20
0
int main()
{
	Node a={'1',0};
	Node b={'2',&a};
	Node c={'3',&b};
	Node d={'4',&c};
	Node * head = &d;

	printlist(head);
	//head=reverse(head);
	printlist(reverse2(head));

	return 0;

}
Example #21
0
void				itoa(int n, char s[])
{
	int				i;
	int				sign;

	if ((sign = n) < 0)
		n = -n;
	i = 0;
	do {
		s[i++] = n % 10 + '0';
	} while ((n /= 10) > 0);
	if (sign < 0)
		s[i++] = '-';
	s[i] = '\0';
	reverse2(s);
}
Example #22
0
NodePtr reverse2(NodePtr first)
{
	NodePtr cur, last;

	if (NULL == first || NULL == first->next)
		return first;

	cur = first;
	while (cur->next->next)
		cur = cur->next;

	last = cur->next;
	cur->next = NULL;
	reverse2(first);
	last->next = cur;

	return last;
}
Example #23
0
int main()
{
	vector<int> v;
	
	cout << "Enter a sequence of integers (enter | to quit loop): ";
	int n;
	while (cin >> n)
		v.push_back(n);
	
	cout << "Reversing with reverse1(): ";
	v = reverse1(v);
	print(v);

	cout << "Reversing with reverse2(): ";
	reverse2(v);
	print(v);

	return 0;
}
Example #24
0
int main()
{
	vector<string> v;
	
	cout << "Enter a sequence of strings (enter \"quit\" to exit loop): ";
	string str;
	while (cin >> str && str != "quit")
		v.push_back(str);
	
	cout << "Reversing with reverse1(): ";
	v = reverse1(v);
	print(v);

	cout << "Reversing with reverse2(): ";
	reverse2(v);
	print(v);

	return 0;
}
Example #25
0
File: lc.c Project: Henry/Leda
struct list* reverse(struct list* a)
{
    return reverse2(a, 0);
}
Example #26
0
void testReverse3() {
  vector<int> v1;
  vector<int> v2;
  CHECKEQ(reverse2(v1), v2);
}
Example #27
0
void testReverse2() {
  vector<int> v1 {1};
  vector<int> v2 {1};
  CHECKEQ(reverse2(v1), v2);
}
Example #28
0
void testReverse() {
  vector<int> v1 {1, 2, 3, 4};
  vector<int> v2 {4, 3, 2, 1};
  CHECKEQ(reverse2(v1), v2);
}
Example #29
0
void reverseBack(void **A, int n) {
  reverse2(A, n/2, n-1);
} // end reverseBack
Example #30
0
Vec2 Level::Builder::transform(Vec2 v) {
  for (auto m : reverse2(mapStack)) {
    v = m(v);
  }
  return v;
}